// log
function getScrollOffset() {
if (window.pageXOffset) {
return {
x: window.pageXOffset,
y: window.pageYOffset,
}
} else {
return {
x: document.body.scrollLeft + document.documentElement.scrollLeft,
y: document.body.scrollTop + document.documentElement.scrollTop,
}
}
}
console.log(getScrollOffset())
// log
// 1440 為標準寬度
console.log(window.innerWidth)
元素的大小
<!-- log -->
<div id="box" style="width:100px;height:100px;background:red;"></div>
// log
let box = document.getElementById('box')
console.log(box.getBoundingClientRect()) // 不常用
console.log(box.offsetWidth)
console.log(box.offsetHeight)
console.log(box.offsetLeft)
console.log(box.offsetTop)
console.log(box.offsetParent)
對于無定位父級的元素,回傳相對檔案的坐標,對于有定位父級的元素,回傳相對于最近的有定位的父級的目標,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/1024.html
標籤:面向對象
上一篇:集合的簡單思路
