我发现了一个小的jQuery cookie脚本,这样当用户第一次访问站点时,站点顶部就会出现一个div;但是用户可以选择关闭这个div,然后他们的选择会在一小段时间内被记住。
现在它工作得很好,但我想尝试应用一个.hide。对脚本显示“快速”,但更改.css属性起作用。但是,如果我刷新,会有一些bug:它仍然可以记住我的选择,但是扩展/类不能在正确的位置。
有人能帮上忙吗?JS代码:
$(document).ready(function() {
// LEFT COLUMN:
// When the collapse button is clicked:
$('.collapse').click(function() {
$('.collapse').css("display","none");
$('.expand').css("display","block");
$('#actionbar').css("height","0px");
$.cookie('actionbar', 'collapsed');
});
// When the expand button is clicked:
$('.expand').click(function() {
$('.expand').css("display","none");
$('.collapse').css("display","block");
$('#actionbar').css("height","70px");
$.cookie('actionbar', 'expanded');
});
// COOKIES
// Left column state
var actionbar = $.cookie('actionbar');
// Set the user's selection for the left column
if (actionbar == 'collapsed') {
$('.collapse').css("display","none");
$('.expand').css("display","block");
$('#actionbar').css("height","0px");
};
});和我的CSS:
.expand {
width:11px;
height:11px;
background:red;
position:absolute;
left:100px;
top:90px;
display:none;
}
.collapse {
width:11px;
height:11px;
background:red;
position:absolute;
right:5px;
top:4px;
}发布于 2012-01-14 07:18:17
也许不是对类进行cookie,而是尝试调用事件。例如,另存为展开或折叠,但放置结束页脚本来检查cookie和折叠/展开属性,然后在coorect元素上执行单击操作?
https://stackoverflow.com/questions/8858470
复制相似问题