dimanche 19 avril 2015

Accordion Jquery Multi-menu nav

I'm doing an accordion menu bar, problem is when i click a link without a children menu the links that has children are still opened, Can somebody help me on how to fix or improve my jquery, what i want is like.. If i click the link without child, all accordion are set to close.



function initMenu() {
$(".sub-menu").hide();
$('#accordion1 li a').click(
function () {
var checkElement = $(this).next();
if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
checkElement.slideUp('normal');
return false;
}
if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#accordion1 ul:visible').not(checkElement.parentsUntil('#accordion1')).slideUp('normal');
checkElement.slideDown('normal');
return false;
}
});
$('.current-menu-item').parentsUntil('#accordion1').slideDown('normal');
}
$(function () {
initMenu();
});
$(function () {
var selector = '.menu li';
$(selector).on('click', function () {
$(selector).removeClass('active');
$(this).addClass('active');
});
$('.menu').delegate('li', 'click', function () {
$(this).addClass('active').siblings().removeClass('active');
});
});


here the JSFIDDLE


Aucun commentaire:

Enregistrer un commentaire