-
element.ownerDocument.document直接返回當(dāng)前節(jié)點的頂層document對象 - element
.clientTop: 返回元素頂部邊框的寬度 - window.
pageYoffset===window.scrollY;pageYoffset是scrollY別名,返回文檔在垂直方向已滾動的像素值。 - element
.getBoundingClientRect().top返回的是相對視口窗口頂部的距離 不是相對整個文檔網(wǎng)頁
如果有滾動條,想計算相對整個網(wǎng)頁的距離那就是
window.scrollY+element.getBoundingClientRect().top
- element
.offsetTop返回當(dāng)前元素相對于其 offsetParent元素的頂部內(nèi)邊距的距離。
offsetParent :指向最近的(指包含層級上的最近)包含該元素的定位元素或者最近的 table,td,th,body元素
- element.
scrollTop:元素的內(nèi)容頂部(卷起來的)到它的視口可見內(nèi)容(的頂部)的距離的度量
element必須是有滾動條的才能取到scrollTop,否則為0 比如默認的滾動頁面下:window.scrollY==document.documentElement.scrollTop
-
clientHeight:element.clientHeight:元素內(nèi)部的高度(單位像素),包含內(nèi)邊距,但不包括水平滾動條、邊框和外邊距
document.documentElement.clientHeight===window.innerHeight:視口窗口的高度document.body.clientHeight:網(wǎng)頁元素內(nèi)容高度document.documentElement.scrollHeight:網(wǎng)頁元素正文的高度,

image.png
判斷一個元素是否在可視區(qū)域: 距離視口的top 在
-自身的高度 ~ document.documentElement.clientHeight之間 即:0<ele.getBoundingClientRect().top+ele.clientHeight<document.body.clientHeight+ele.clientHeight
9.window.getComputedStyle(element, [pseudoElt]) 計算屬性樣式
-
Function.prototype.bind():創(chuàng)建一個新函數(shù),該新函數(shù)在被調(diào)用時將其關(guān)鍵字設(shè)置為提供的值,并在調(diào)用新函數(shù)時提供給定的參數(shù)序列。
const Template=(args)=>({})
Note thatTemplate.bind({})is a standard JavaScript technique for making a copy of a function.