0

It looks like in chrome:

$(window).width()

is not matching the CSS3 media queries, when there are scroll bars. Without scrollbars it matches fine.

Does anyone know a good work around?

Here is the example: http://codepen.io/krismeister/pen/LmJFt/

Make your browser, about 600px wide then drag across teh 550px width. Then toggle the scrollbars. I'm on chrome Version 33.0.1750.152

1

2 Answers 2

2

I found this workaround on a similar stack thread:

CSS media queries and JavaScript window width do not match

Got a jsFiddle to work for you. http://jsfiddle.net/j839b/

Using this

function recordWidth(){
  var w=window,
      d=document,
      e=d.documentElement,
      g=d.getElementsByTagName('body')[0],
      x=w.innerWidth||e.clientWidth||g.clientWidth,
      y=w.innerHeight||e.clientHeight||g.clientHeight;
    $('#last-width').text(x);
}

From http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript

Sign up to request clarification or add additional context in comments.

Comments

0

Im on chrome and seems to change with me: No scrolls: last recorded width - win:1920, doc:1920, body:1904 With scrolls: last recorded width - win:1905, doc:1905, body:1889

1 Comment

You have to move in the 550px range, where the media query is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.