Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Created July 5, 2011 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbranyen/1066042 to your computer and use it in GitHub Desktop.
Save tbranyen/1066042 to your computer and use it in GitHub Desktop.
doubletap-improved?
function doubleTouch(element, callback) {
if ((!element && !callback) || (!callback && typeof element !== 'function')) {
return;
} else if (!callback && typeof element === 'function') {
callback = element;
element = document;
}
var taps = 0;
function clear() {
taps = 0;
}
element.addEventListener('touchend', function(e) {
if(++taps === 2) {
clear();
return callback(e);
}
window.setTimeout(clear, 500);
});
}
// Pretend jQuery
function $(s) { return document.querySelector(s); };
// document.body
doubleTouch($('body'), function(e) {
// Do something
});
// document
doubleTouch(function(e) {
// Do something
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment