js monitor page size changes
background
There are the following scenarios, for example, when the window size changes, our elements also need to automatically change the layout, then we need to monitor the page size change to achieve the corresponding function
Solution
Listening to page size changes can resize
be achieved by listening to events
window.addEventListener('resize', () => {
const w = document.documentElement.clientWidth;
const h = document.documentElement.clientHeight;
console.log('页面大小发生了变化', `宽度:${
w}`, `高度:${
h}`);
});