栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

什么是被动事件监听器?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

什么是被动事件监听器?

被动事件侦听器是一种新兴的网络标准,是Chrome51附带的一项新功能,可极大提高滚动性能。

通过消除滚动以阻止触摸和滚轮事件监听器的需求,它使开发人员可以选择更好的滚动性能。

问题:
所有现代浏览器都具有线程化滚动功能,即使在运行昂贵的Javascript时,滚动操作也可以平稳运行,但是这种优化由于需要等待任何

touchstart
touchmove
处理程序的结果而被部分挫败,这可能会通过调用来完全阻止滚动
preventDefault()
在事件上。

解:

{passive: true}

通过将触摸或滚轮侦听器标记为被动,开发人员保证处理程序不会调用

preventDefault
以禁用滚动。
This frees the browser up to respond to scrolling immediately without waiting for Javascript, thusensuring a reliably smooth scrolling experience for the user

document.addEventListener("touchstart", function(e) {    console.log(e.defaultPrevented);  // will be false    e.preventDefault();   // does nothing since the listener is passive    console.log(e.defaultPrevented);  // still false}, Modernizr.passiveeventlisteners ? {passive: true} : false);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442219.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号