chrome开发人员由于目标被视为被动而无法在被动事件侦听器中阻止Default

时间:2019-10-11 15:06:55

标签: javascript google-chrome passive-event-listeners

除了显示chrome开发人员时,我有一些可以正常工作的javascript代码。有了这个我得到Unable to preventDefault inside passive event listener due to target being treated as passive

代码如下:

function moveDown(event,subnavs){
const navbar = document.getElementsByClassName('main-navigation')[0]                       

const purpleDiv = document.getElementsByClassName('home-vision')[0]                  

console.log(navbar,subnavs,purpleDiv)

var menu = document.getElementById("menu-1")
console.log(menu)
console.log(event)
console.log(event.target)

var x= "250px"  
purpleDiv.style.marginTop = x   

}

(function(){
const subnavs = document.getElementsByClassName('sub-menu')  


for (let i = 0; i < subnavs.length; i++) {
    subnavs[i].addEventListener('mouseover', function(event) {
    moveDown(event, subnavs);
    }, {passive: false});
}
})()

0 个答案:

没有答案