js monitor page size changes

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 resizebe achieved by listening to events

window.addEventListener('resize', () => {
    
    
	const w = document.documentElement.clientWidth;
	const h = document.documentElement.clientHeight;
	console.log('页面大小发生了变化', `宽度:${
      
      w}`, `高度:${
      
      h}`);
});

Guess you like

Origin blog.csdn.net/Boale_H/article/details/130595671