[英]remember menu state vertical multilevel navigation
I've tried to make a vertical multilevel navigation, but I can't seem to intergrate a code in order to make the last menu state be remembered when a new page is loaded. 我试图进行垂直多级导航,但是似乎无法整合代码以使在加载新页面时记住上一个菜单状态。
I've searched for options using hash location, and I tried using cookies, I just don't know how to include it into my excisting code. 我已经使用哈希位置搜索了选项,并且尝试使用Cookie,但我不知道如何将其包含在现有代码中。
Well, I would like some help with this. 好吧,我希望对此有所帮助。 You can see the menu here: http://blendit3d.nl/index_animatie.html
您可以在此处查看菜单: http : //blendit3d.nl/index_animatie.html
Thnx Sandra 桑德拉·桑德拉(Thnx Sandra)
$(document).ready(function() {
$('.sub').hide();
$('.nav > li > a').click(function(e) {
// if new link is opened:
//function setCookie (GetElementById){
// document.cookie = cname + "=" + cvalue + "; " + expires;
//}
e.preventDefault();
$('.sub:visible').slideUp('slow');
$('.subsub').hide();
$('.open').removeClass('open');
$(this).parent().addClass('open').next().slideDown(400).not(':animated');
return false;
});
$('.subsub').hide();
$('.sub li a').click(function() {
$('.subsub:visible').slideUp('300');
$('.opensub').removeClass('opensub');
$(this).parent().addClass('opensub').next().slideDown('slow');
return false;
});
});
Something like this should help - 这样的事情应该有所帮助-
For absolute URL only - What this does is it gets current url and match it with the menu markup and adds active
class.. 仅适用于绝对网址-它的作用是获取当前网址并将其与菜单标记匹配并添加
active
类。
$(function(){
// Get current url
// Select an a element that has the matching href and apply a class of 'active'. Also prepend a - to the content of the link
var url = window.location.href;
$('.menu a[href="'+url+'"]').addClass('current_page_item');
});
For Relative URL - This code should work for relative URLs as well. 对于相对URL-此代码也应适用于相对URL。 I would recommend you to use this code.
我建议您使用此代码。
$(function(){
var url = window.location.href;
$('.menu a').filter(function() {
return (url.indexOf(this.href) > -1)
}).addClass('.active');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.