Skip to content

Instantly share code, notes, and snippets.

@designly1
Created April 29, 2019 20:02
Show Gist options
  • Save designly1/ba1b51bfa238116454621039a9fa9e99 to your computer and use it in GitHub Desktop.
Save designly1/ba1b51bfa238116454621039a9fa9e99 to your computer and use it in GitHub Desktop.
jQuery Touch Demo
$.fn.touch = function (callback) {
$.touchMove = false;
$.touch = false;
$.touchAction = "";
$(this).on("click", function (e) {
if (!$.touch) {
$.touchAction = 'click';
let callbackReal = callback.bind(this);
callbackReal(this, e);
} else {
$.touch = true;
}
$.touch = false;
});
$(this).on("touchend", function (e) {
$(this).blur();
if (typeof e.touches != typeof undefined) {
e.preventDefault();
$.touch = true;
if ($.touchMove) {
$.touchMove = false;
return false;
} else {
$.touchAction = 'touch';
let callbackReal = callback.bind(this);
callbackReal(this, e);
}
}
});
$(this).on("touchmove", function (e) {
$.touchMove = true;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment