Last Updated: February 25, 2016
·
694
· nsteiner

Media Queries in JS

An interesting way to let CSS talk to JS directly. Found in this comment

It uses getComputedStyle which has it's limitations, but could be substituted with jQuery's .css() as described here

CSS

body:after {
      content: 'fluid';
      display: none;
    }
@media only screen and (min-width: 64em) {
      body:after { content: 'fixed'; }
    }

JS

var size = window.getComputedStyle(document.body,':after').getPropertyValue('content')

1 Response
Add your response

Nice :)

over 1 year ago ·