Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.