JS basics review_ scroll bar

Time:2020-9-2
// 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 is the standard width
console.log(window.innerWidth)

The size of the element

// log
let box = document.getElementById('box')
console.log ( box.getBoundingClientRect ()) // not commonly used
console.log(box.offsetWidth)
console.log(box.offsetHeight)
console.log(box.offsetLeft)
console.log(box.offsetTop)
console.log(box.offsetParent)

For elements with no locating parent, returns the coordinates relative to the document. For elements with an anchor parent, returns the target relative to the nearest positioned parent.