保持div滚动条的状态 使用cookie记录位置

<div class="mint" id="mint" style="position: absolute; left: 5px; top: 5px; right: 5px;
        bottom: 5px; width: auto; height: auto; overflow: scroll" onscroll="setCookie('t',this.scrollTop)">
        <div class="report_plfs">
            <a href="javascript:void(0);" class="radioA" showdiv="iconList"><b class="r_icon1"></b>
                <em>图标排列</em> </a><a href="javascript:void(0);" showdiv="groupSort" class="radioA r_checked">
                    <b class="r_icon2"></b><em>分组排列</em> </a>
        </div> 

</div>

<script>
     function setCookie(cookieName, cookieValue) {
         var today = new Date();
         var expire = new Date();
         nMinutes = 100;
         expire.setTime(today.getTime() + nMinutes * 60 * 1000);
         document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
     };

     function getCookie(c_name) {
         if (document.cookie.length > 0) {
             c_start = document.cookie.indexOf(c_name + "=");
             if (c_start != -1) {
                 c_start = c_start + c_name.length + 1;
                 c_end = document.cookie.indexOf(";", c_start);
                 if (c_end == -1) c_end = document.cookie.length;
                 return unescape(document.cookie.substring(c_start, c_end));
             }
         }
         return "";
     };

     function getscrolltop() {
         var t = getCookie("t")
         if (t != "") { document.getElementById("mint").scrollTop = parseInt(t); }
     };

     window.onload = function () {
         getscrolltop();
     };
  </script>

posted @ 2015-06-17 16:37  @vip_c  阅读(343)  评论(0编辑  收藏  举报