Created
October 12, 2013 11:56
-
-
Save agaase/6949222 to your computer and use it in GitHub Desktop.
The tap event on an element.
This file contains 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
window.onload = function(){ | |
var startPosX=0,startPosY=0; | |
var elements = $("tapHighlightJS"); | |
for(var i=0;i<elements.length;i++){ | |
var el = $(elements[i]); | |
el.bind('touchstart', function(ev){ | |
var touchobj = ev.originalEvent.changedTouches[0]; | |
startPosX = touchobj.pageX; | |
startPosY = touchobj.pageY; | |
}).bind('touchend', function(ev){ | |
var touchobj = ev.originalEvent.changedTouches[0]; | |
if(Math.abs(touchobj.pageX-startPosX)<5 ? (Math.abs(touchobj.pageY-startPosY)<5?true:false):false){ | |
var tapEl = $(ev.originalEvent.target); | |
tapEl.css("opacity","0.3"); | |
setTimeout(function(){ | |
tapEl.css("opacity","1"); | |
},2000); | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment