`
Sharpleo
  • 浏览: 565226 次
  • 性别: Icon_minigender_1
  • 来自: newsk
社区版块
存档分类
最新评论

div跟滚动条移动

    博客分类:
  • js
 
阅读更多

	 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";  //离左端距离                       
     }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics