首页 文章

无法阻止被动事件监听器内的默认 - Swipebox Mobie

提问于
浏览
1

我正在使用Swipebox:http://brutaldesign.github.io/swipebox/我知道我可以使用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>

问题是我在mobie上通过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

我该如何解决这个问题,非常感谢你

1 回答

  • 0

    被动事件侦听器是一种事件,您承诺浏览器永远不会调用event.preventDefault() . 这样浏览器可以优化诸如滚动/触摸之类的动作,因为浏览器可以假设开发人员不会被取消(例如禁用滚动) .

    默认情况下,Chrome会根据版本56启用此功能:https://www.chromestatus.com/features/5093566007214080 . 他们将此更改作为优化滚动的一种方式 .

    如果您不希望发生这种情况,可以将{passive:false}添加为 .addEventListener 的第三个参数 .

    阅读更多关于被动事件的信息:https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md

相关问题