I have the following javascript code that's not working:
function moveDown(subnavs) {
const navbar = document.getElementsByClassName('main-navigation')[0]
const purpleDiv = document.getElementsByClassName('home-vision')[0]
console.log(navbar,subnavs,purpleDiv)
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', moveDown(subnavs), {passive:false})
}
})()
When the page comes up, purpleDiv is immediately moved down 250px. When subnav is mouseover, console says Unable to preventDefault inside passive event listener due to target being treated as passive.
I am not 100% clear on your intent but here I alter the code to put in semi-colons to not force the browser to guess where to insert those and put a function in to allow passing the event and the other parameter you have (not sure the intent here) but calling it instead when adding the event handler was probably not your intent.
No clue on your
preventDefaultnote as that was not in the illustrated code supplied but I illustrate some stuff in the function called.