首页 文章

Jquery Cookies ,滑动面板问题的状态

提问于
浏览
0

我的滑动面板有点问题,我有一个带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");

};

谢谢你的回复..

2 回答

  • 1

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

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

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

    我'm not sure which cookie plugin you'重新使用,所以我不能告诉你如何做到这一点的具体细节 .

相关问题