Javascript 元素宽高,偏移以及滚动位置

来源:互联网 发布:淘宝助理无法打印 编辑:程序博客网 时间:2024/06/05 05:00

总结一下 Javascript 和 jQuery 中的一些宽高和位置的获取,虽然经过本人试验,但是还是建议看到的人能亲自试一下。

纸上得来终觉浅,绝知此事要躬行。

Javascript

:–: 元素 窗口、文档 屏幕 宽高 elem.clientWidth
elem.clientHeight

elem.offsetWidth
elem.offsetHeight

elem.scrollWidth
elem.scrollHeight window.outerWidth
window.outerHeight

window.innerWidth
window.innerHeight

document.documentElement.clientWidth
document.documentElement.clientHeight

document.body.clientWidth
document.body.clientHeight screen.availWidth

screen.width 偏移位置 offsetLeft
offsetTop

clientLeft
clientTop 滚动距离 scrollLeft
scrollTop window.scrollY
document.body.scrollTop
document.documentElement.scrollTop

这里写图片描述

jQuery

:–: 元素 窗口、文档 屏幕 宽高 width()
innerWidth()
outerWidth() $(window).width()
$(document).width()
$(‘body’).width() screen.availWidth
screen.width 偏移位置 offset().left
offset().top

position().left
position().top 滚动距离 scrollLeft()
scrollTop() $(‘body’).scrollTop()

这里写图片描述

0 0
原创粉丝点击