Created
August 21, 2017 07:23
-
-
Save terrymun/967157a6a328ff17e873b425103dd733 to your computer and use it in GitHub Desktop.
Stop touch events from bubbling up in iOS Safari
This file contains hidden or 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
/* | |
* Stops touchevent from bubbling up using jQuery | |
*/ | |
$(document).on('touchstart touchmove touchend', function(e) { | |
// Example of a parentSelector | |
// var parentSelector = '#parentElement'; | |
if ($(e.target).closest(parentSelector).length) | |
e.preventDefault(); | |
}); |
This file contains hidden or 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
/* | |
* Stops touchevent from bubbling up using JavaScript | |
*/ | |
document.addEventListener('touchend', bubbleStop, false); | |
document.addEventListener('touchmove', bubbleStop, false); | |
document.addEventListener('touchend', bubbleStop, false); | |
var bubbleStop = function(e) { | |
// If you need polyfill for .closest(), see: https://stackoverflow.com/a/35294561/395910 | |
// Example of a parentSelector | |
// var parentSelector = '#parentElement'; | |
if(e.target.closest(parentSelector)) | |
e.preventDefault(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment