我正在使用 Swipebox:http://brutaldesign.github.io/swipebox/ 我知道我可以像这样使用滑动框幻灯片打开内容
// Link to click
<a href="#mydiv" class="my-swipebox">Click to show</a>
// And the div in html
<div id="#mydiv">Click <a href="http://example.com">Here</div>
问题是当它在手机上通过 swipebox 打开时,我无法单击此 div 内的链接(在桌面上工作得很好)
chrome 浏览器显示此日志:
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080
preventDefault @ js_3q9o_g1v9VMwOb38KwiIL35eXGTsWaJ31hpdemJVNbY.js:5
dispatch @ js_3q9o_g1v9VMwOb38KwiIL35eXGTsWaJ31hpdemJVNbY.js:5
v.handle @ js_3q9o_g1v9VMwOb38KwiIL35eXGTsWaJ31hpdemJVNbY.js:5
如何解决这个问题,非常感谢
最佳答案
被动事件监听器是您向浏览器 promise 永远不会调用 event.preventDefault() 的事件。这样浏览器就可以优化滚动/触摸等操作,因为浏览器可以假设开发人员不会被取消(例如禁用滚动)。
Chrome 根据版本 56 默认启用此功能:https://www.chromestatus.com/features/5093566007214080 。他们进行此更改是为了优化滚动。
如果您不希望发生这种情况,可以将 { Passive: false } 添加为 .addEventListener
的第三个参数。
了解有关被动事件的更多信息:https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
关于javascript - 无法阻止被动事件监听器内的默认行为 - Swipebox Movie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45120638/