2011-01-05 63 views
0

我的滑动面板有一个小问题,我有一个带有2个滑动面板的页面(左右)。这些面板有一个'幻灯片按钮',你可以通过点击来减少面板。Jquery饼干,滑动面板问题的状态

我使用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"); 

}; 

感谢答复..

回答

1

如果您使用的是我正在考虑的JQuery cookie插件,您可以将Cookie设置为可在任何地方使用。

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

没关系,谢谢! – bAN 2011-01-06 07:17:34

1

我不能完全肯定,但我认为你要cookie中设置domain/,以便它可以在整个域中使用。

我不确定你正在使用哪个cookie插件,所以我不能告诉你关于如何这样做的具体信息。