Can I change the media query using javascript / jQuery?

前端 未结 7 931
逝去的感伤
逝去的感伤 2020-12-10 15:50

I have a style.css with a media query. In my javascript-file, I have a value for the desired mobile-width stored in a variable.

By changing the variable, I want to c

7条回答
  •  有刺的猬
    2020-12-10 16:30

    You can set the rule directly using .media.mediaText of document.styleSheets[0].cssRules

    document.styleSheets[0].cssRules[0].media.mediaText = /* new media rule here */;
    

    plnkr http://plnkr.co/edit/qzLO5J4KlWZLQnjMIy7i?p=preview

提交回复
热议问题