[Javascript] Window.matchMedia()

window.matchMedia() allow to listen to browser window size changes and trigger the callback for different media query size.3d

let mql = window.matchMedia('(max-width: 600px)');

 

 

you can attach a listener to it:code

mql.addListener(() => console.log('changes'));

So when the window size is smaller than 600px, it matches is true otherwise is false.blog

When you resize the window, it will log out "changes" in console.it

相關文章
相關標籤/搜索