📜  收听文档高度变化 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:59.159000             🧑  作者: Mango

代码示例1
// create an Observer instance
const resizeObserver = new ResizeObserver(entries => 
  console.log('Body height changed:', entries[0].target.clientHeight)
)

// start observing a DOM node
resizeObserver.observe(document.body)

// click anywhere to rnadomize height
window.addEventListener('click', () =>
  document.body.style.height = Math.floor((Math.random() * 5000) + 1) + 'px'
)