javascript - 如何为 jquery 1.x 修复 chrome 的非被动元素问题
问题描述
我有一个项目,我们使用带有 dataTables 功能的 jquery 1.x。此功能似乎适用于 Firefox 浏览器,但对于 chrome,它不起作用,也不会在控制台中出现任何错误。它只是发出警告
向阻止滚动的“touchmove”/“touchstart”事件添加了非被动事件侦听器。考虑将事件处理程序标记为“被动”以使页面更具响应性。
我尝试了一些解决方案,例如preventDefault()
将脚本添加或添加到被动错误,但没有成功。
喜欢
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
this.addEventListener("touchstart", handle, { passive: false });
} else {
this.addEventListener("touchstart", handle, { passive: true });
}
}
};
jQuery.event.special.touchmove = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
this.addEventListener("touchmove ", handle, { passive: false });
} else {
this.addEventListener("touchmove ", handle, { passive: true });
}
}
};
这与jquery版本控制有关吗?如果是,那么我是否需要将它迁移到数据表(虽然现在它在 Firefox 中得到了支持)。
解决方案
我创建了一个包,passive
根据使用情况添加具有适当值的属性preventDefault
。请参阅被动事件支持
试一试,确保只传递导致警告的事件:
<script>
window.passiveEvents = ['touchstart', 'touchmove']
</script>
<script type="text/javascript" src="node_modules/passive-events-support/dist/main.js"></script>
这解决了jquery
我的问题。
推荐阅读
- java - 错误:未知列“0_”。在“where子句”中
- r - 如何将以本地语言表示的字符串布尔值转换为布尔值
- python - 城市、道路和网络流量。通过另一个表中的索引列对一个表进行分组/聚合?
- azure - 无法更改 Azure ML 笔记本中的虚拟环境
- sql - 使用“create as”语句创建索引组织表的 Oracle 问题
- excel - GetSaveAsFilename 使用单元格值作为文件标题
- java - 如何调试 javax.net.ssl 包
- javascript - 尽管在 Postman 工作,但出现 400 错误,可能的原因是什么?
- powershell - 是否可以使用 Powershell 从模板创建 Microsoft 团队?
- arrays - 如何根据 IlNumerics 中的数组中的多个条件过滤行