Answer the question
In order to leave comments, you need to log in
How to fix the dropdown menu so that it doesn't close when the page is opened?
How to fix the dropdown menu so that it doesn't close when the page is opened? here is a link to the site super-gun.ru
Example:
Click on
Pneumatic Pistols opens a drop-down menu
, click on GAMO Pistols opens the directory is highlighted GAMO Pistols and the menu does not close.
Menu code
function initMenu() {
jQuery(".vmenu li.parent > a").click(function(eventObject){return false});
jQuery('.vmenu ul').hide();
jQuery('.vmenu li.active ul').show();
jQuery('.vmenu li a').click(
function() {
jQuery(this).next().slideToggle('normal');
}
);
}
jQuery(document).ready(function() {initMenu();});
function allClose(){
var list = document.getElementById("menu").getElementsByTagName("ul");
for(var i=0;i<list.length;i++){
list[i].style.display = "none";
}
}
function openMenu(node){
var subMenu = node.parentNode.getElementsByTagName("ul")[0];
subMenu.style.display == "none" ? subMenu.style.display = "block" : subMenu.style.display = "none";
}
Answer the question
In order to leave comments, you need to log in
As an option, place on each of the pages a script that adds the display: block property to the item.
Try replacing your code with this one. Should work. This saves one open menu and does not highlight the active menu item.
var menu = jQuery('#menu');
menu.find('ul').each(function(index, value) {
value.id = 'opened_section_' + index;
});
function initMenu() {
var openedMenuElem = JSON.parse(localStorage.getItem('superGunSettings')).openedMenuId;
jQuery(".vmenu li.parent > a").click(function(eventObject){return false});
jQuery('.vmenu ul').hide();
jQuery('.vmenu li.active ul').show();
jQuery('.vmenu li a').click(
function() {
jQuery(this).next().slideToggle('normal');
}
);
jQuery('#' + openedMenuElem).show();
}
jQuery(document).ready(function() {initMenu();});
function allClose(){
var list = document.getElementById("menu").getElementsByTagName("ul");
for(var i=0;i<list.length;i++){
list[i].style.display = "none";
}
}
function openMenu(node){
var subMenu = node.parentNode.getElementsByTagName("ul")[0];
localStorage.setItem('superGunSettings', JSON.stringify({openedMenuId: subMenu.id}));
subMenu.style.display == "none" ? subMenu.style.display = "block" : subMenu.style.display = "none";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question