Created
April 4, 2013 21:04
-
-
Save Prinzhorn/5314333 to your computer and use it in GitHub Desktop.
When preventing touch events from their default action, you can't click links or form elements. By checking if the move distance was small (i.e. it was just a tap) we can trigger a click on this element.
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
//Check if it was more like a tap. | |
var distanceY = initialTouchY - currentTouchY; | |
var distanceX = initialTouchX - currentTouchX; | |
var distance2 = distanceX * distanceX + distanceY * distanceY; | |
//Why use Math.sqrt when you can just compare the square number ;-). | |
if(distance2 < 49) { | |
//It was a tap, grab the element and click it. | |
var elementToClick = document.elementFromPoint(initialTouchX, initialTouchY); | |
elementToClick.click(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iscroll creates a mouseEvent on the fly that theoretically should be better than .click(). Have to try that.