0

我有一个简单的代码,它允许我在两个 div 之间切换,它们是两个子导航的包装(#sub-nav-wrap 是替代导航)。它们固定在浏览器的底部:

$(function(){
$('.button').click(function(){
    $('#sub-nav-wrapmin').toggle();
    $('#sub-nav-wrap').toggle();
  });   
});

我希望做的是保持每个 div 的状态与用户在页面刷新后选择的状态相同,即使单击新的子标题菜单也将保持不变,而不是诉诸默认状态。

html是这样的:

<!--- Main Sub Wrap --->
<div id="bottom-wrap">
<!-- Mini Sub Nav -->

<div id="sub-nav-wrapmin" class="snWrap divone">
        <div id="sn-contentmin">
            <div id="sn-likemin"></div> 
            <div id="sn-coffeesml"></div>
            <div id="sn-sharemin"></div>
            <div id="sn-commentsml"></div>
            <div id="toggle-barmin">
                    <div id="sn-sidebrdrmin"></div>
                    <div class="sn-toggle button"></div>
           </div>
              <ul class="sn-comicsmin menu">
                <li><a class="sn-comics" style="background-position: right top" href="#comic.html">Comic</a></li>
                <li><a class="sn-archive" href="#archive.html">Archive</a></li>
                <li><a class="sn-vote" href="#vote.html">Vote</a></li>
                <li><a class="sn-spotlight" href="#spotlight.html">Spotlight</a></li>
            </ul>
      </div>
</div>
<!-- Sub Nav -->
<div id="sub-nav-wrap" class="snWrap divtwo">
    <div id="sub-nav-container">
         <div id="sub-nav-content">

                <div id="sn-bnrlft"></div>
                <div id="sn-bnrrgt"></div>
                <div class="sn-dividelft"></div>
                <div class="sn-dividergt"></div>
                <div id="sn-likebg"></div>
                <div id="sn-coffeebtn">
                </div>
                <div id="sn-sharebtn"></div>
                <div id="sn-commentbtn"></div>    
                <div id="toggle-bar">
                    <div id="sn-sidebrdr"></div>
                    <div class="toggle button"></div>
                </div>            
        </div>
        <div id="sub-nav-brdr">
            <ul class="sub-nav-comics menu">
                <li><a class="comics" style="background-position: right top" href="#comic.html">Comic</a></li>
                <li><a class="archive" href="#archive.html">Archive</a></li>
                <li><a class="vote" href="#vote.html">Vote</a></li>
                <li><a class="spotlight" href="#spotlight.html">Spotlight</a></li>
            </ul>
        </div>
    </div>
</div>

CSS是这样的:

#sub-nav-wrap {
    display: none;  
}

这是我第一次问,我一直在绞尽脑汁想用这个网站上的其他类似代码让它工作,但没有任何效果。请帮忙...

4

1 回答 1

2

你几乎做对了,只是写了很多多余的:)

$(function(){
    if($.cookie('submin_visible') == 'true') {
        $('#sub-nav-wrapmin').show();
        $('#sub-nav-wrap').hide();
    } else {
        $('#sub-nav-wrapmin').hide();
        $('#sub-nav-wrap').show();
    }

    $('.button').click(function(){
        $('#sub-nav-wrapmin').toggle();
        $('#sub-nav-wrap').toggle();

        var isVisible = $('#sub-nav-wrapmin').is(':visible').toString();
        $.cookie('submin_visible', isVisible);
    });
});
于 2012-07-29T15:05:41.657 回答