default-passive-events All In One
default-passive-events All In One
解决滚动背景的问题
$ yarn add default-passive-events
$ yarn i default-passive-events
document.addEventListener('mouseup', onMouseUp);
// {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, true);
// {passive: true, capture: true}
document.addEventListener('mouseup', onMouseUp, false);
// {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false});
// {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false, capture: false});
// {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: false, capture: true});
// {passive: false, capture: true}
document.addEventListener('mouseup', onMouseUp, {passive: true, capture: false});
// {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, {passive: true, capture: true});
// {passive: true, capture: true}
demo
require('default-passive-events');
preventBackScroll = (e) => {
e.preventDefault();
e.stopPropagation();
}
renderModal = (e) => {
// 阻止滚动
document.addEventListener('touchmove', this.preventBackScroll, { passive: false, capture: true });
// 遮罩层实现代码省略
return <div onClose={(e) => {
// 关闭遮罩层时放开
document.removeEventListener('touchmove', this.preventBackScroll, { passive: false, capture: true });
}}></div>
}
refs
https://github.com/zzarcon/default-passive-events
https://www.npmjs.com/package/default-passive-events
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14831014.html
未经授权禁止转载,违者必究!