0

The following line would run the function inside it when the width is above 770px and below 1024px - the question is, how can I include the width of the scrollbar to it?

if (width < 1024 && width > 770) {}

I already tried implementing window.pageXOffset or window.innerWidth with no hope!

Daniele
  • 1,938
  • 16
  • 24
  • possible duplicate of [Jquery $(window).width() excluding scrollbar width?](http://stackoverflow.com/questions/16802036/jquery-window-width-excluding-scrollbar-width) – SlashmanX Feb 21 '14 at 11:47
  • Mate I already did my research, I tried the answers on there but none is working! –  Feb 21 '14 at 11:52
  • You said you tried `pageXOffset` and `innerWidth`. Did you try `outerWidth` ? – SlashmanX Feb 21 '14 at 11:53
  • yes I tried it like "if ($(window).outerWidth () < 770) {" is the way I applied it correct? –  Feb 21 '14 at 11:54
  • Check this link ... http://stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript – Asons Feb 21 '14 at 11:55

1 Answers1

0

if (window.outerWidth< 1024 && window.outerWidth > 770) {}

window.outerWidth gets the width of the outside of the browser window. It represents the width of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.

https://developer.mozilla.org/en-US/docs/Web/API/Window.outerWidth

SlashmanX
  • 2,489
  • 18
  • 16
  • There is a small problem however, It worked on this function nicely: http://jsfiddle.net/pvC6s/ but when not on this one http://jsfiddle.net/a7Rps/ why is that mate? –  Feb 21 '14 at 12:05
  • 2nd one works fine for me after i added some `console.log()`to test it out – SlashmanX Feb 21 '14 at 12:09
  • Did you use $(window).on("load resize", function() { if (window.outerWidth < 1024 && window.outerWidth > 770) { –  Feb 21 '14 at 12:20
  • This is not supported by IE8 ... this is: http://stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript – Asons Feb 21 '14 at 13:40