媒体查询
const x = window.matchMedia("(max-width: 400px)");
function myFunction (x) {
if (x.matches) {
document.body.style.backgroundColor = 'red'
} else {
document.body.style.backgroundColor = 'blue'
}
}
myFunction(x)
x.addListener(myFunction);
网友评论