Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Media Query in Script tag

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43174
    mdyorke
    Participant

    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:

    #127106
    rosspenman
    Participant

    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

    #127225
    mdyorke
    Participant

    Thanks rosspenman…got it to work!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.