-
-
Save vosidiy/8c5d07babc905a1099a7fc811f59d83a to your computer and use it in GitHub Desktop.
BS5 basic hover js
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
document.addEventListener("DOMContentLoaded", function(){ | |
// make it as accordion for smaller screens | |
if (window.innerWidth > 992) { | |
document.querySelectorAll('.navbar .nav-item').forEach(function(everyitem){ | |
everyitem.addEventListener('mouseover', function(e){ | |
let el_link = this.querySelector('a[data-bs-toggle]'); | |
if(el_link != null){ | |
let nextEl = el_link.nextElementSibling; | |
el_link.classList.add('show'); | |
nextEl.classList.add('show'); | |
} | |
}); | |
everyitem.addEventListener('mouseleave', function(e){ | |
let el_link = this.querySelector('a[data-bs-toggle]'); | |
if(el_link != null){ | |
let nextEl = el_link.nextElementSibling; | |
el_link.classList.remove('show'); | |
nextEl.classList.remove('show'); | |
} | |
}) | |
}); | |
} | |
// end if innerWidth | |
}); | |
// DOMContentLoaded end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment