Skip to content

Instantly share code, notes, and snippets.

@cemerson
Created April 15, 2013 13:50
Show Gist options
  • Save cemerson/5388204 to your computer and use it in GitHub Desktop.
Save cemerson/5388204 to your computer and use it in GitHub Desktop.
JavaScript: Touch/Click and Hold
var element;
document.addEventListener('touchstart', function(event) {
event.preventDefault();
var touch = event.touches[0];
element = document.elementFromPoint(touch.pageX,touch.pageY);
}, false);
document.addEventListener('touchmove', function(event) {
event.preventDefault();
var touch = event.touches[0];
if (element !== document.elementFromPoint(touch.pageX,touch.pageY)) {
touchleave();
}
}, false);
function touchleave() {
console.log ("You're not touching the element anymore");
}
@rishabhzvky
Copy link

@cemerson
Hey Cemerson, hope you are doing good. Could you tell me the current compatibility of this code in react.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment