xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-05-31 13:06  xgqfrms  阅读(783)  评论(1编辑  收藏  举报