【问题标题】:Jquery cookies, states of sliding panel problemJquery cookie,滑动面板问题的状态
【发布时间】:2026-01-04 01:20:06
【问题描述】:

我的滑动面板有点问题,我有一个带有 2 个滑动面板(左右)的页面。这些面板有一个“滑动按钮”,您可以通过单击它来缩小面板。

我使用 cookie 来记录面板的状态,因此当您更改页面面板时保持折叠或展开状态。但效果不是很好,实际上是为页面记录状态。如果我更改页面,面板将扩展(默认位置),但如果我返回页面,它将消失。是否可以忽略 cookie 中的路径并为所有网站使用 cookie? jQuery代码:

$('#rightfold').click(function () {
    if ($('.menudroite').is(':visible')) {
        $('.menudroite').hide("slide", { direction: "right" }, 400);
        $.cookie('rightfold', 'collapsed');
        $('.triggerdroite').animate({ backgroundColor: "#B2C9D1" }, 1000);
        $('#rightfold').animate({ color: "#000000" }, 1000);           
    }
    else {
        $('.menudroite').show("slide", { direction: "right" }, 400);
        $.cookie('rightfold', 'extended');
        $('.triggerdroite').animate({ backgroundColor: "#6c7a7f" }, 1000);
        $('#rightfold').animate({ color: "#d9f4ff" }, 1000); 

    }

});
$('#leftfold').click(function () {
    if ($('.menugauche').is(':visible')) {
        $('.menugauche').hide("slide", { direction: "left" }, 400);
        $.cookie('leftfold', 'collapsed');
        $('.triggergauche').animate({ backgroundColor: "#B2C9D1" }, 1000);
        $('#leftfold').animate({ color: "#000000" }, 1000); 
    }
    else {
        $('.menugauche').show("slide", { direction: "left" }, 400);
        $.cookie('leftfold', 'extended');
        $('.triggergauche').animate({ backgroundColor: "#6c7a7f" }, 1000);
        $('#leftfold').animate({ color: "#d9f4ff" }, 1000); 


    }

});

// COOKIES

var leftfold = $.cookie('leftfold');
var rightfold = $.cookie('rightfold');

// Set the user's selection for the left column
if (leftfold == 'collapsed') {
    $('.menugauche').css("display", "none");

};
// Set the user's selection for the right column
if (rightfold == 'collapsed') {
    $('.menudroite').css("display", "none");

};

感谢您的回复..

【问题讨论】:

    标签: asp.net jquery cookies


    【解决方案1】:

    如果您正在使用我正在考虑的 JQuery cookie 插件,您可以像这样将 cookie 设置为随处可用。

    $.cookie('leftfold', 'extended', {path: '/'});
    

    【讨论】:

      【解决方案2】:

      我不完全确定,但我认为您想将 cookie domain 设置为 / 以便它可以在整个域中使用。

      我不确定您使用的是哪个 cookie 插件,因此我无法为您提供如何执行此操作的具体信息。

      【讨论】: