admin管理员组文章数量:1313737
I'm using Google Page Speed Insights to optimize my page speed. It tells me to not use passive listeners to improve scrolling performance. I know how to do it with vanilla javascript.
window.addEventListener(
'scroll',
() => {
handleScroll();
},
{ passive: true }
);
How to do this with JQuery?
I'm using Google Page Speed Insights to optimize my page speed. It tells me to not use passive listeners to improve scrolling performance. I know how to do it with vanilla javascript.
window.addEventListener(
'scroll',
() => {
handleScroll();
},
{ passive: true }
);
How to do this with JQuery?
Share Improve this question asked Oct 24, 2020 at 15:26 jixodojjixodoj 3294 silver badges12 bronze badges1 Answer
Reset to default 7This worked for me. Just add it directly after jQuery has been loaded
// Passive event listeners //Two slight variations in setting the flag but seems to acplish same thing
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ) {
this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
}
};
jQuery.event.special.touchmove = {
setup: function( _, ns, handle ) {
this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });
}
};
jQuery.event.special.wheel = {
setup: function( _, ns, handle ){
this.addEventListener("wheel", handle, { passive: true });
}
};
jQuery.event.special.mousewheel = {
setup: function( _, ns, handle ){
this.addEventListener("mousewheel", handle, { passive: true });
}
};
本文标签: javascriptJQueryHow to marke touch and wheel event listeners as passiveStack Overflow
版权声明:本文标题:javascript - JQuery - How to marke touch and wheel event listeners as `passive` - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741958714a2407141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论