Unable to preventDefault inside passive event

錯誤:

Unable to preventDefault inside passive event listener due to target being treated as passive.javascript

解決方案:

安裝:java

$ yarn add default-passive-events

簡單的示例:node

require('default-passive-events');

引入js:chrome

<script type="text/javascript" src="node_modules/default-passive-events/dist/index.js"></script>

使用cdn:bash

<script type="text/javascript" src="https://unpkg.com/default-passive-events"></script>

示例和輸出:ide

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}

 

緣由:ui

https://www.chromestatus.com/features/5093566007214080spa

相關資源:code

https://zhuanlan.zhihu.com/p/24385322cdn

相關文章
相關標籤/搜索