记住菜单状态垂直多级导航

时间:2014-11-23 08:02:24

标签: javascript jquery menu state

我尝试进行垂直多级导航,但我似乎无法集成代码,以便在加载新页面时记住最后一个菜单状态。

我已经使用哈希位置搜索了选项,我尝试使用Cookie,我只是不知道如何将其包含在我的解码代码中。

好吧,我想要一些帮助。 您可以在此处查看菜单:http://blendit3d.nl/index_animatie.html

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;
                });

        });

1 个答案:

答案 0 :(得分:1)

这样的事情应该有所帮助 -

仅限绝对网址 - 这样做是为了获取当前网址并将其与菜单标记相匹配并添加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');
});

对于相对URL - 此代码也适用于相对URL。我建议你使用这段代码。

$(function(){ 
   var url = window.location.href;

   $('.menu a').filter(function() {
       return (url.indexOf(this.href) > -1)
   }).addClass('.active');
});
相关问题