三大家族

offset系列

? ? ? offsetWidth?offsetHeight?獲取元素真實(shí)的寬高大?。償?shù)值)

? ? ? ?offsetParent?獲取距離元素最近的有定位的父節(jié)點(diǎn),如果沒(méi)有找到,找body

? ? ? ?offsetLeft?offsetTop???獲取元素到offsetParent之間真實(shí)的距離(純數(shù)值)

? ? ? 以上的共同點(diǎn):

? ? ? ? 都是只讀屬性,設(shè)置無(wú)效

? ? ? 如果設(shè)置,通過(guò)style來(lái)設(shè)置

scroll家族

成員:?scrollWidth?scrollHeight?scrollLeft?scrollTop

scrollWidth?scrollHeight?獲取元素里面的內(nèi)容寬高

scrollLeft?scrollTop?獲取內(nèi)容卷曲的距離

滾動(dòng)事件??onscroll?當(dāng)滾動(dòng)的時(shí)候會(huì)觸發(fā)


????????獲取整個(gè)頁(yè)面的卷曲距離?==>?有兼容

????????對(duì)老版本的瀏覽器:?通過(guò)html的scrollTop去獲取,如果要是獲取不到,去通過(guò)body的scrollTop去獲取

????????html?==>?document.documentElement

????????document.documentElement.scrollTop

????????document.body.scrollTop

????????console.log(document.documentElement.scrollTop?||?document.body.scrollTop);


????????新版本瀏覽器:

????????window.pageYOffset??獲取垂直方向的卷曲距離

????????window.pageXOffset??獲取水平方向的卷曲距離

????????新老兼容寫(xiě)法

????????console.log(window.pageYOffset?||?document.documentElement.scrollTop?||?document.body.scrollTop);

????????給頁(yè)面注冊(cè)滾動(dòng)事件

????????建議給window來(lái)注冊(cè),?這樣兼容性最好

client家族

?clientWidth??clientHeight?clientTop??clientLeft

clientWidth??clientHeight??獲取可視區(qū)的寬高

?clientTop??clientLeft?獲取元素的上邊框、左邊框的大小

????????獲取頁(yè)面可視區(qū)的寬高?==>?有兼容

????????老版本:通過(guò)html的clientWidth?,或者是通過(guò)body的clientWidth來(lái)獲取

????????console.log(document.documentElement.clientWidth?||?document.body.clientWidth);

????????console.log(document.documentElement.clientHeight?||?document.body.clientHeight);

????????新版本:?window.innerWidth??window.innerHeight

????????新老兼容

????????console.log(window.innerWidth?||?document.documentElement.clientWidth?||?document.body.clientWidth);

????????onresize?當(dāng)瀏覽器的窗口大小發(fā)生改變的時(shí)候觸發(fā)

????????給頁(yè)面注冊(cè),?建議給window注冊(cè)

????????window.onresize?=?function?()?{

????????????console.log(window.innerWidth?||?document.documentElement.clientWidth?||?document.body.clientWidth);

????????}

? ? ? 三大家族總結(jié)

? ? ? ? 1.?offset系列

? ? ? ? ? 成員:offsetWidth?offsetHeight?offsetLeft?offsetTop?offsetParent

? ? ? ? ? ?作用:獲取元素真實(shí)的寬高大小,獲取元素到offsetParent之間真實(shí)的距離

? ? ? ? 2.?scroll系列

? ? ? ? ? ? 成員:scrollWidth?scrollHeight?scrollLeft?scrollTop

? ? ? ? ? ? 常用的:scrollTop

? ? ? ? ? ?作用:獲取頁(yè)面的垂直方向的卷曲距離

? ? ? ? ?獲取:?window.pageYOffset

? ? ? ? ?事件:滾動(dòng)事件?onscroll

? ? ? 3.?client系列

? ? ? ? ? 成員:clientWidth?clientHeight?clientLeft?clientTop

? ? ? ? ? 常用的:clientWidth?clientHeight

? ? ? ? ? 作用:獲取頁(yè)面的可視區(qū)的寬高

? ? ? ? ? ? 獲?。?window.innerWidth?window.innerHeight

? ? ? ? ? ?事件:onresize??窗口大小發(fā)生改變觸發(fā)

? ? ? ? 給頁(yè)面注冊(cè)的事件(document、window)

? ? ? ?給window注冊(cè)的

? ? ? ?1.?window.onscroll

? ? ? ?2.?window.onresize

? ? ? ? 3.?window.onload

? ? ? ?其他的給document注冊(cè)即可

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文是針對(duì)剛學(xué)編程的小白,都是一些基礎(chǔ)知識(shí),如果想了解更多深層一點(diǎn)的東西,歡迎移步本人博客!! 博客地址 點(diǎn)擊跳轉(zhuǎn)...
    西巴擼閱讀 743評(píng)論 0 2
  • 整理自撩課學(xué)院 www.itlike.com 一、offSet家族 1、概念 offSet 自己的,用于獲取元素尺...
    冰河_295d閱讀 1,833評(píng)論 0 0
  • JS三大家族 JS的三大家族主要是Offset、Scroll、Client,通過(guò)對(duì)三大家族不同屬性的靈活使用,我們...
    Peak_One閱讀 1,752評(píng)論 0 5
  • ----------------- offset --------------------- offset家族特點(diǎn)...
    青橙1閱讀 686評(píng)論 0 0
  • 1.offset家族 offset這個(gè)單詞本身是--偏移,補(bǔ)償,位移的意思。 js中有一套方便的獲取元素尺寸的辦法...
    那一抹流星閱讀 622評(píng)論 0 1

友情鏈接更多精彩內(nèi)容