我使用Chrome扩展程序修改缩放增量,并在控制台中抛出此错误:
window.addEventListener("mousewheel", function( event ) {
if(enabled){
//console.log("Scrolling Before: ",scrolling);
if(!zooming){
if(( event.wheelDeltaY > 0 || event.wheelDeltaY < 0 ) && !event.ctrlKey && !scrolling)
scrolling = true;
}
//console.log("Scrolling: ",scrolling);
if(!zooming && !scrolling){
if(event.ctrlKey){
zooming = true;
tempZoomLevel = zoomLevel;
if( event.wheelDeltaY > 0 ) {
tempZoomLevel += zoomIncrement;
}
if( event.wheelDeltaY < 0 ) {
tempZoomLevel -= zoomIncrement;
}
if((Date.now() - lastZoomEvent) > zoomDelay){
lastZoomEvent = Date.now();
zooming = false;
zoomLevel = tempZoomLevel;
chrome.runtime.sendMessage({zoom: zoomLevel, lastZoom:lastZoomEvent, from:"content"}, function(response) {
});
}
else
zooming = false;
}
event.preventDefault();
event.stopPropagation();
}
/*else{
}*/
return false;
}
}, {capture: true} ); /* Passive event listeners Mikhoul */
我尝试修改扩展程序以添加标记以使事件处理程序被动,但它似乎无法工作,我不知道为什么?
以下是代码:
{capture: true}
最后你会看到我已经添加了&#34;标志&#34; v6.x
但我总是在控制台中出现此错误:
at the documentation for configuration
我错过了什么让听众被动并停止在控制台中抛出此错误?
问候!
答案 0 :(得分:1)
您需要在事件处理程序中设置passive: true
,如下所示:
window.addEventListener("mousewheel", function( event ) {
// all of your function code
// ...
}, { passive: true})