警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件(Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event han)
var passiveEvent = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function () {
passiveEvent = true;
}
});
window.addEventListener("test", null, opts);
} catch (e) { }
// in my case I need both passive and capture set to true, change as you need it.
passiveEvent = passiveEvent ? { capture: true, passive: true } : true;
//if you need to handle mouse wheel scroll
var supportedWheelEvent: string = "onwheel" in HTMLDivElement.prototype ? "wheel" :
document.onmousewheel !== undefined ? "mousewheel" : "DOMMouseScroll";
使用:
elementRef.addEventListener("touchstart", handler, passiveEvent);
posted on 2020-12-08 11:40 zhangzongshan 阅读(4844) 评论(0) 收藏 举报
浙公网安备 33010602011771号