Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Having a problem that a collapsible menu in a fixed sidebar is not staying open when the links are clicked (or when the page simply refreshes).

I used the suggestions based on this question about using a cookie to store the div's state but it's not working (toggle state is still not persisting).

I added a link to the plugin (AFTER my jQuery src link):

<script src="js/jquery.cookie.js" type="text/javascript"></script>

And the toggle state still doesn't stay, even live on a .com website.

if ($.cookie('div') == 'open'){
    $('#the_more_div').slideDown('slow');
} else {
    $('#the_more_div').slideUp('slow');
}

$('#hamburger').click(function(){
    $('#the_more_div').slideToggle('slow', function(){
        if ($(this).is(':hidden')) {
            $.cookie('div', 'closed');
        } else {
            $.cookie('div', 'open');
        }
    }); 
});

The toggle works just fine but why wouldn't the_more_div stay open when different links are clicked inside it (or on page refresh).

Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
901 views
Welcome To Ask or Share your Answers For Others

1 Answer

Turns out the issue was an unrelated conflict. The above code does in fact work to install a cookie to make the div status persist.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...