获取当前scrollTop和scrollLeft,兼容XHTML
2020-11-15 01:36
标签:com http blog style class div img code java log javascript 获取当前scrollTop和scrollLeft,兼容XHTML,搜素材,soscw.com 获取当前scrollTop和scrollLeft,兼容XHTML 标签:com http blog style class div img code java log javascript 原文地址:http://www.cnblogs.com/fyima/p/3695714.html 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,那么等于0
12
13 scrollLeft = (document.body.scrollLeft > document.documentElement.scrollLeft) ? document.body.scrollTop : document.documentElement.scrollLeft;
14
15 if(isNaN(scrollLeft) || scrollLeft ;};
16
17 return{scrollTop:scrollTop,scrollLeft:scrollLeft};
文章标题:获取当前scrollTop和scrollLeft,兼容XHTML
文章链接:http://soscw.com/index.php/essay/21355.html