Skip to content

Instantly share code, notes, and snippets.

@FreePhoenix888
Created July 4, 2020 08:11
Show Gist options
  • Save FreePhoenix888/58403dfb464c0dbe1bfd5062d39d7e6b to your computer and use it in GitHub Desktop.
Save FreePhoenix888/58403dfb464c0dbe1bfd5062d39d7e6b to your computer and use it in GitHub Desktop.
DropDownMenuFull
let isMobile = {
Android: function() {return navigator.userAgent.match(/Android/i);},
BlackBerry: function() {return navigator.userAgent.match(/BlackBerry/i);},
iOS: function() {return navigator.userAgent.match(/iPhone|iPad|iPod/i);},
Opera: function() {return navigator.userAgent.match(/Opera Mini/i);},
Windows: function() {return navigator.userAgent.match(/IEMobile/i);},
any: function() {return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());}
};
let body=document.querySelector('body');
if(isMobile.any()){
body.classList.add('touch');
let arrow=document.querySelectorAll('.arrow');
for(i=0; i<arrow.length; i++){
let thisLink=arrow[i].previousElementSibling;
let subMenu=arrow[i].nextElementSibling;
let thisArrow=arrow[i];
thisLink.classList.add('parent');
arrow[i].addEventListener('click', function(){
subMenu.classList.toggle('open');
thisArrow.classList.toggle('active');
});
}
}else{
body.classList.add('mouse');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment