看到網(wǎng)上很多文章都是只針對要么min-width,要么max-width來監(jiān)聽var mql = window.matchMedia('(max-width: 760px)');function screenTest(e) { if (e.matches) { document.body.style.backgroundColor = 'red'; } else { document.body.style.backgroundColor = 'blue'; }}mql.addListener(screenTest);但是如果我這么寫就不管用了var mql = window.matchMedia('(min-width:380) and (max-width: 760px) ');mql.addListener(screenTest);請問怎樣才能同時監(jiān)聽是否滿足最大和最小值?
matchMedia 能否同時監(jiān)聽 min-width和max-width
暮色呼如
2019-02-25 17:35:18