Skip to content

Instantly share code, notes, and snippets.

@Inontran
Created December 21, 2020 01:13
Show Gist options
  • Select an option

  • Save Inontran/a0b6deccdebfa7e4c289bf2c259790b1 to your computer and use it in GitHub Desktop.

Select an option

Save Inontran/a0b6deccdebfa7e4c289bf2c259790b1 to your computer and use it in GitHub Desktop.
пассивные прослушиватели событий для jquery
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 });
}
}
};
@GuidingD
Copy link

GuidingD commented Jun 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment