当前位置: 代码迷 >> Web前端 >> div和滚动条移动
  详细解决方案

div和滚动条移动

热度:78   发布时间:2013-01-28 11:49:56.0
div跟滚动条移动

	 function getScroll() {
         var t, l, w, h;
         if (document.documentElement && document.documentElement.scrollTop) {
             t = document.documentElement.scrollTop;
             l = document.documentElement.scrollLeft;
             w = document.documentElement.scrollWidth;
             h = document.documentElement.scrollHeight;
         }

         else if (document.body) {
             t = document.body.scrollTop;
             l = document.body.scrollLeft;
             w = document.body.scrollWidth;
             h = document.body.scrollHeight;
         }
         return { t: t, l: l, w: w, h: h };
     }

     window.onscroll = function() {
         var v = getScroll();
         var e = document.getElementById("timediv");
         e.style.position = "absolute";
         e.style.top = v.t;  //纵滚动条离顶部距离
         e.style.left = "1140px";  //离左端距离                       
     }
  相关解决方案