Skip to content

Instantly share code, notes, and snippets.

@petrusnog
Created October 14, 2019 14:37
Show Gist options
  • Save petrusnog/70116085f1276578d02b1b0b53796c2d to your computer and use it in GitHub Desktop.
Save petrusnog/70116085f1276578d02b1b0b53796c2d to your computer and use it in GitHub Desktop.
Sistema de dropdowns em jquery
//DROPDOWNS WEART
//Adicione aqui os droptitles
//Dropdowns: Todos os dropdowns
//Close on scroll:Dropdowns que serão fechados mediante scroll
$dropdowns = ["banners", "categories", "painel", "filterby"];
$close_on_scroll = [$dropdowns[2]];
var global_submenu = ".Submenu-dropdown--"; // + droptitle
var global_seta = "#Dropdown-seta--"; // + droptitle
//AÇÕES
//Ações de dropdown
window.removeAllActives = function () {
$(".seta-active").css("transform", "rotate(0deg)");
$(".actived")
.slideUp()
.removeClass("actived");
}
window.OpenMenu = function (submenu, seta) {
submenu.slideDown();
removeAllActives();
submenu.addClass("actived");
seta.addClass("seta-active");
seta.css("transform", "rotate(180deg)");
}
window.CloseMenu = function (submenu, seta) {
submenu.slideUp();
submenu.removeClass("actived");
seta.removeClass("seta-active");
seta.css("transform", "rotate(0deg)");
}
// EVENTOS
//Eventos de dropdown
$dropdowns.forEach(function(droptitle){
var submenu = $(global_submenu + droptitle);
var seta = $(global_seta + droptitle);
$("#Dropdown-" + droptitle).click(function(event){
if (submenu.hasClass("actived")){
CloseMenu(submenu, seta);
}else{
OpenMenu(submenu, seta);
}
});
});
$close_on_scroll.forEach(function(droptitle){
var submenu = $(global_submenu + droptitle);
var seta = $(global_seta + droptitle);
$(window).on("scroll", function(){
CloseMenu(submenu, seta);
});
});
// APAGAR DROPDOWN MEDIANTE CLIQUE FORA DO BALÃO
$("body").click(function(event){
if (event.target.hasAttribute("click")) {
var click = event.target.getAttribute("click")
}else{
var click = "false";
}
console.log(click);
if(click != "true"){
removeAllActives();
}
});
// FIM DE DROPDOWNS WEART
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment