Created
December 21, 2020 01:13
-
-
Save Inontran/a0b6deccdebfa7e4c289bf2c259790b1 to your computer and use it in GitHub Desktop.
пассивные прослушиватели событий для jquery
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
| jQuery.event.special.touchstart = { | |
| setup: function( _, ns, handle ){ | |
| if ( ns.includes("noPreventDefault") ) { | |
| this.addEventListener("touchstart", handle, { passive: false }); | |
| this.addEventListener("touchmove", handle, { passive: false }); | |
| this.addEventListener("scroll", handle, { passive: false }); | |
| } else { | |
| this.addEventListener("touchstart", handle, { passive: true }); | |
| this.addEventListener("touchmove", handle, { passive: true }); | |
| this.addEventListener("scroll", handle, { passive: true }); | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will not tirck google pagespeedtest. To trick it, in jquery.min.js instead
a.addEventListener(n,g)i wrote
a.addEventListener(n,g,{ passive: (n=='scroll' ||n=='mousewheel' || n=='touchstart'?true:false)}))And then turn on active event listener on touchstart, because I use preventDefault on it
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
this.addEventListener("touchstart", handle, { passive: false });
}
};
This will trich google pagespeed test