生活随笔
收集整理的這篇文章主要介紹了
offset;scroll;client
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
DOM元素對象的屬性/方法之offset(Height,Width,Left,Parent,Top);scroll(Height,Width,Left,Top);client(Height,Width);
一、相對位置
offsetHeight: 返回,任何一個元素的高度包括邊框和填充,但不是邊距;offsetWidth: 返回元素的寬度,包括邊框和填充,但不是邊距;offsetLeft: 返回當前元素的相對水平偏移位置的偏移容器;offsetTop: 返回當前元素的相對垂直偏移位置的偏移容器;offsetParent: 返回元素的偏移容器; 二、滾動距離scrollHeight: 返回整個元素的高度(包括帶滾動條的隱蔽的地方);scrollLeft: 返回當前視圖中的實際元素的左邊緣和左邊緣之間的距離;scrollTop: 返回當前視圖中的實際元素的頂部邊緣和頂部邊緣之間的距離;scrollWidth: 返回元素的整個寬度(包括帶滾動條的隱蔽的地方); 三、可視距離clientHeight: 在頁面上返回內容的可視高度(不包括邊框,邊距或滾動條);clientWidth: 在頁面上返回內容的可視寬度(不包括邊框,邊距或滾動條);<!DOCTYPE html>
<html lang=
"en"><head><meta charset=
"utf-8"></head><style
type=
"text/css">* {padding:0;margin:0;}</style><body><div id=
"offset">offset...</div><script
type=
"text/javascript">console.log(offset.offsetWidth +
',' + offset.offsetHeight +
','+ offset.offsetTop +
','+ offset.offsetLeft +
',' + offset.offsetParent);//200,200,,20,20;// 設置offset的緊鄰父級元素bodybackground =
'red';offset.offsetParent.style.background =
'#e1e1e1'; //$(
"body").offsetParent().css(
"background-color",
"red");alert(offset.offsetHeight = 999);//可以虛擬性的更改其值;</script></body>
</html>
復制代碼
總結
以上是生活随笔為你收集整理的offset;scroll;client的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。