The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Media Query in Script tag

  • # March 5, 2013 at 6:00 pm

    Hey, Im working on a project where an element changes when the user scrolls a specified amount down the page…The code I have works but the problem is that I need to add a media query so I can change the scroll amount depending on the screen size. I have read some blogs on how to do this but can’t seem to get it to work…Any ideas??


    # March 5, 2013 at 6:15 pm

    The best thing to use for this is probably just `window.innerWidth` (I think there’s some weirdness with this in old IE – but jQuery’s $(window).width() sorts that).

    If you need full-on Media Queries, you could use `window.matchMedia`.

    # March 6, 2013 at 2:26 pm

    Thanks rosspenman…got it to work!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed