看到網(wǎng)上很多文章都是只針對(duì)要么min-width,要么max-width來(lái)監(jiān)聽(tīng)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);但是如果我這么寫(xiě)就不管用了var mql = window.matchMedia('(min-width:380) and (max-width: 760px) ');mql.addListener(screenTest);請(qǐng)問(wèn)怎樣才能同時(shí)監(jiān)聽(tīng)是否滿足最大和最小值?
matchMedia 能否同時(shí)監(jiān)聽(tīng) min-width和max-width
暮色呼如
2019-02-25 17:35:18