这是我的代码......
var menuToggle = false;
$(document).ready(function () {
// Init Tabs
$("#ipsg-tabs").tabs();
// Init Tooltips
$(function () {
$('.ipsg-tab').tooltip();
});;
// Init Menu
accordionMenu();
// Toggle Menu
$('.ipsg-logo-menu-btn').click(function () {
if (!menuToggle) {
menuToggle = true;
$('.sg-accordion > .ipsg-nav-items').hide();
$('.sg-accordion h3').removeClass('state-selected');
$('.ipsg-container').addClass('ipsg-menu-collapse');
} else {
menuToggle = false;
$('.ipsg-container').removeClass('ipsg-menu-collapse');
}
});
});
function accordionMenu() {
var allPanels = $('.sg-accordion > .ipsg-nav-items');
var menuLeaving = false;
$('.sg-accordion > h3 > a').click(function () {
if (!menuToggle) {
if (!$(this).parent().hasClass('state-selected')) {
allPanels.slideUp('fast');
$('.sg-accordion h3').removeClass('state-selected');
$(this).parent().next().slideDown('fast');
$(this).parent().addClass('state-selected');
} else {
allPanels.slideUp('fast');
$('.sg-accordion h3').removeClass('state-selected');
}
}
return false;
});
$('.sg-accordion > h3 > a').mouseenter(function () {
if (menuToggle) {
menuLeaving = false;
$('.sg-accordion > .ipsg-nav-items').hide();
$('.sg-accordion h3').removeClass('state-selected');
$(this).parent().next().show();
$(this).parent().addClass('state-selected');
}
});
$('.sg-accordion > .ipsg-nav-items').mouseenter(function () {
if (menuToggle) {
menuLeaving = false;
}
});
$('.sg-accordion > h3 > a').mouseleave(function () {
if (menuToggle) {
menuLeaving = true;
setTimeout(function () {
if (menuLeaving) {
$('.sg-accordion > .ipsg-nav-items').hide();
$('.sg-accordion h3').removeClass('state-selected');
}
}, 400);
}
});
$('.sg-accordion > .ipsg-nav-items').mouseleave(function () {
if (menuToggle) {
menuLeaving = true;
setTimeout(function () {
if (menuLeaving) {
$('.sg-accordion > .ipsg-nav-items').hide();
$('.sg-accordion h3').removeClass('state-selected');
}
}, 400);
}
});
}
我正在尝试关闭或打开我的切换菜单,具体取决于页面重新加载。因此,如果我正在使用汉堡包菜单,并点击链接,我希望汉堡包菜单在重新加载后保持不变。打开菜单也是如此,如果我点击这些链接,我想要它,以便菜单在重新加载时保持打开状态。
有人有什么想法吗?
答案 0 :(得分:0)
我会使用localStorage或cookies。您可以设置一个变量,以便您可以决定是否应该打开或关闭菜单。
答案 1 :(得分:0)
以前问过。您可以使用cookie,因为它易于实施和维护 链接在这里 Jquery UI Accordion menu saving menu state even after refresh