codepen & js demos Mutation Observer & customize resize event listener & demo
Mutation Observer & customize resize event listener & demo
https://codepen.io/webgeeker/pen/YjrZgg
Mutation Observer
https://javascript.ruanyifeng.com/dom/mutationobserver.html
https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserver
// todo
https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event
const heightOutput = document.querySelector('#height');
const widthOutput = document.querySelector('#width');
function reportWindowSize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
window.onresize = reportWindowSize;
// OR
window.addEventListener('resize', reportWindowSize);