Created
April 15, 2013 13:50
-
-
Save cemerson/5388204 to your computer and use it in GitHub Desktop.
JavaScript: Touch/Click and Hold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cemerson
Hey Cemerson, hope you are doing good. Could you tell me the current compatibility of this code in react.