重新加载后jQuery显示并激活所选项目ul?

时间:2014-03-17 17:03:53

标签: jquery menu html-lists

我有一个jQuery动画菜单,但是当我点击一个项目(菜单点)时,该网站会重新加载一个节目内容和菜单的第一个视图,但没有选择的菜单项。

如何在重新加载后激活项目并打开所选的ul?

$('a.forward').next().hide();

/* Forward Button */
$('a.forward').click(function(e) {
    e.preventDefault();

    $(this).next().clone(true, true).appendTo(".subnav").css({
        position: "absolute", 
        left:"190px", 
        top:"0", 
        display:"block"}).animate({
            left:"0"
    }, 300);

    $(this).closest("ul").animate({
        left:"-190px",
    }, 300);

    return false;
});

/* Back Button */
$('a.back').click(function(e) {
    e.preventDefault();

    $(this).closest("ul").prev().animate({
        left:"0",
    }, 300);

    $(this).closest("ul").animate({
        left:"200px",
    }, 300, "linear",function(){$(this).remove()});
    return false;
});

var targetAnchor;
$.each ($('ul.lsb-menu a'), function() {
    if( this.href == window.location ) {
        targetAnchor = this;
        return false;
    }
});

var parent = $(targetAnchor).closest('li');

while(true) {
    parent.addClass('active');

    if( $(parent).parents('ul.lsb-menu').length <= 0 ) break;
}

实施例: http://jsfiddle.net/Mh35b/5/

0 个答案:

没有答案