Grow your CSS skills. Land your dream job.

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??

    Code:

    # 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`.

    https://developer.mozilla.org/en/docs/DOM/window.innerWidth
    http://api.jquery.com/width/

    https://developer.mozilla.org/en-US/docs/DOM/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.

*May or may not contain any actual "CSS" or "Tricks".