Created
August 5, 2015 00:08
-
-
Save stpettersens/07d28d3519c9711b7716 to your computer and use it in GitHub Desktop.
Touch pad tap code.
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
function isTouchScreenDevice() { | |
var isTouch = false; | |
var ua = navigator.userAgent; | |
if(ua.indexOf("Mobile") !== -1 || ua.indexOf("Tablet") !== -1) { | |
isTouch = true; | |
} | |
return isTouch; | |
} | |
window.onload = function() { | |
if(!isTouchScreenDevice()) alert('Not a touch screen device!'); | |
// Touch controls. | |
var start; | |
document.addEventListener('touchstart', function(event) { | |
event.preventDefault(); | |
start = new Date().getTime(); | |
}); | |
document.addEventListener('touchend', function(event) { | |
event.preventDefault(); | |
var elapsed = new Date().getTime() - start; | |
if((elapsed < 600) && (elapsed > 0)) { | |
alert('Short tap'); | |
} | |
else { | |
alert('Long tap'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment