Created
February 6, 2022 02:33
-
-
Save rickd-uk/d950bdd2767ccd403b43cf15d7eafbbc to your computer and use it in GitHub Desktop.
JS - Delayed Event (Mouseover, Mouseout)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myDelayedThing() { | |
var mySelectors = document.querySelectorAll('.something'); | |
// Loop through mySelectors | |
for(var i = 0; i < menuLinks.length; i++) { | |
// Add 'open' class on mouseover | |
menuLinks[i].addEventListener('mouseover', function() { | |
this.classList.add('open'); | |
}); | |
// Remove 'open" class with a delay | |
menuLinks[i].addEventListener('mouseout', function () { | |
var node = this; // Allows us to access 'this' within the timeout function | |
setTimeout(function() { | |
node.classList.remove('open'); | |
}, 500) | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment