Created
April 29, 2019 20:02
-
-
Save designly1/ba1b51bfa238116454621039a9fa9e99 to your computer and use it in GitHub Desktop.
jQuery Touch Demo
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
$.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