繁体   English   中英

刷新页面时,Slidetoggle保留当前状态

[英]Slidetoggle to retain current state when page is refreshed

我有这段代码,该代码可以正常工作,但是每当我重新加载或刷新页面时,它就会返回到初始关闭状态。 即使页面重新加载后,我也希望保留上一个切换状态。 我似乎无法解决这个问题。

我的代码是:

var $answers = $('.contentbar');
$(".titlebar").click(function () {
    var $ans = $(this).next(".contentbar").stop(true).slideToggle(500);
    $answers.not($ans).filter(':visible').stop(true).slideUp();
})

有一个名为jQuery.cookie的插件。 使用它可以检查是否已经有用户设置的手风琴,并且根据首选项,可以默认显示/隐藏东西。

var $answers = $('.contentbar');
$(".titlebar").click(function () {
    if (!$.cookie('contentbar'))
        var $ans = $(this).next(".contentbar").stop(true).slideToggle(500);
    else
    {
        var $ans = $($.cookie('contentbar')).next(".contentbar").stop(true).slideToggle(500);
        $.cookie('contentbar', this);
    }
    $answers.not($ans).filter(':visible').stop(true).slideUp();
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM