mirror of
https://github.com/nanoy42/coope
synced 2024-12-24 07:53:47 +00:00
27 lines
954 B
JavaScript
27 lines
954 B
JavaScript
|
/* When the user clicks on the button,
|
||
|
toggle between hiding and showing the dropdown content */
|
||
|
function dropdown(target) {
|
||
|
var dropdowns = document.getElementsByClassName("dropdown-content");
|
||
|
var i;
|
||
|
for (i = 0; i < dropdowns.length; i++) {
|
||
|
var openDropdown = dropdowns[i];
|
||
|
if (openDropdown.classList.contains('show')) {
|
||
|
openDropdown.classList.remove('show');
|
||
|
}
|
||
|
}
|
||
|
document.getElementById(target).classList.toggle("show");
|
||
|
}
|
||
|
|
||
|
// Close the dropdown menu if the user clicks outside of it
|
||
|
window.onclick = function(event) {
|
||
|
if (!event.target.matches('.dropbtn')) {
|
||
|
var dropdowns = document.getElementsByClassName("dropdown-content");
|
||
|
var i;
|
||
|
for (i = 0; i < dropdowns.length; i++) {
|
||
|
var openDropdown = dropdowns[i];
|
||
|
if (openDropdown.classList.contains('show')) {
|
||
|
openDropdown.classList.remove('show');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|