要获取当前页面的滚动条纵坐标位置,用:document.documentElement.scrollTop;而不是:document.body.scrollTop;documentElement 对应的是 html 标签,而 body 对应的是 body 标签. 在标准w3c下,document.body.scrollTop恒为0,需要用document.documentElement.scrollTop来代替;如果你想定位鼠标相对于页面的绝对位置时,你会发现google里面1000篇文章里面有
一.获取css的大小 1.第一种通过内联样式 var box = document.getElementById('box'); var w = box.style.width; var h = box.style.height; 2.通过计算元素的大小(但是在ie情况下有一个问题,那就没写widht和height的css就返回auto); var style = window.getComputedStyle ? window.getComputedStyle(box,null) : null