jQuery用cookie显示/隐藏

时间:2012-01-13 23:07:01

标签: jquery css html5 jquery-cookie

我找到了一个小的jQuery cookie脚本,以便当用户第一次访问该站点时,我的站点顶部会出现一个div;但是用户可以选择关闭该div,然后在短时间内记住他们的选择。

现在它工作正常,但我想尝试应用.hide。显示'快'到脚本,但更改.css属性工作。但是,如果我刷新了一些错误:它仍然可以记住我的选择,但扩展/ collaspe无法在正确的位置。

有人可以帮忙吗? 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;
}

1 个答案:

答案 0 :(得分:0)

也许不是对课程进行cookie,而是尝试cking事件。例如,保存为展开或折叠,但放置结束页面脚本以检查该cookie和折叠/展开属性,然后对coorect元素执行单击操作?