Skip to content

Instantly share code, notes, and snippets.

@omniosi
Created April 11, 2014 19:19
Show Gist options
  • Save omniosi/10493889 to your computer and use it in GitHub Desktop.
Save omniosi/10493889 to your computer and use it in GitHub Desktop.
pointer events code by @girlie_mac as seen in netm.ag may 2014
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
var isTouchSupported = 'ontouchstart' in window;
var isPointerSupported = navigator.pointerEnabled;
var isMSPointerSupported = naviogator.msPointerEnabled;
var downEvent = isTouchSupported ? 'touchstart' : (isPointerSupported ? 'pointerdown' : (isMSPointerSupported ? 'MSPointerDown' : 'mousedown'));
document.body.addEventListener(downEvent, function(e){
//console.log('pointerdown',e.clientX,e.clientY);
var x = isTouchSupported ? e.targetTouches[0].clientX : e.clientX;
var y = isTouchSupported ? e.targetTouches[0].clientY : e.clientY;
}, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment