Skip to content

Instantly share code, notes, and snippets.

@Lwdthe1
Last active May 9, 2016 20:27
Show Gist options
  • Save Lwdthe1/42caae5001db92ce24f502dc909ea391 to your computer and use it in GitHub Desktop.
Save Lwdthe1/42caae5001db92ce24f502dc909ea391 to your computer and use it in GitHub Desktop.
A simple jQuery function to capture double tap (or click) event on an element.
(function($){
$.fn.setDoubleTap = function(doubleTap){
var lastTapTime;
var doDoubleTap = function() {
//set the time of this click
var timeNow = new Date().getTime();
//calculate the time since last click
var timeSinceLastTap = timeNow - lastTapTime;
//check if it's been long enough to deem this click a part of a double tap sequence
if((timeSinceLastTap < 600) && (timeSinceLastTap > 0)){
// it was a double tap
//do your double tap action
doubleTap();
} else {
// too much time has passed to deem this a part of a double tap sequence
//do something else if necessary
//alert("SINGLE")
}
//set the last tap time to now
lastTapTime = new Date().getTime();
}
//catch the user's click event on this element
this.on("click", doDoubleTap);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment