1 // JavaScript Document
 2 /*  用法与测试:
 3     var myScroll = getScroll();
 4     alert("myScroll.scrollTop:" + myScroll.scrollTop);
 5     alert("myScroll.scrollLeft:" + myScroll.scrollLeft);
 6 */
 7 function getScroll(){
 8         var scrollTop,scrollLeft;
 9         scrollTop = (document.body.scrollTop > document.documentElement.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;//兼容浏览器
10         
11         if(isNaN(scrollTop) || scrollTop < 0){ scrollTop = 0;};//如果获取到非数字或者是小于0,那么等于0
12         
13         scrollLeft = (document.body.scrollLeft > document.documentElement.scrollLeft) ? document.body.scrollTop : document.documentElement.scrollLeft;
14         
15         if(isNaN(scrollLeft) || scrollLeft < 0){ scrollLeft = 0;};
16         
17         return{scrollTop:scrollTop,scrollLeft:scrollLeft};

 

posted on 2014-04-28 09:42  Durian`Yi  阅读(253)  评论(0编辑  收藏  举报