js获取页面元素距离浏览器工做区顶端的距离

js获取页面元素距离浏览器工做区顶端的距离

先介绍几个属性:(暂时只测了IE和firefox,实际上我工做中用到的最多的是chrome)javascript

 网页被卷起来的高度/宽度(即浏览器滚动条滚动后隐藏的页面内容高度)html

(javascript)        document.documentElement.scrollTop //firefoxjava

(javascript)        document.documentElement.scrollLeft //firefoxchrome

(javascript)        document.body.scrollTop //IE浏览器

(javascript)        document.body.scrollLeft //IEpost

(jqurey)             $(window).scrollTop() url

(jqurey)             $(window).scrollLeft()spa

 网页工做区域的高度和宽度  
firefox

(javascript)       document.documentElement.clientHeight// IE firefox       htm

(jqurey)             $(window).height()

 元素距离文档顶端和左边的偏移值  

(javascript)        DOM元素对象.offsetTop //IE firefox

(javascript)        DOM元素对象.offsetLeft //IE firefox

(jqurey)             jq对象.offset().top

(jqurey)             jq对象.offset().left