How can I make jQuery do something if my screen width is less than 960 pixels? The code below always fires the 2nd alert, regardless of my window size:
if (screen.width < 960) {
alert('Less than 960');
}
else {
alert('More than 960');
}
How can I make jQuery do something if my screen width is less than 960 pixels? The code below always fires the 2nd alert, regardless of my window size:
if (screen.width < 960) {
alert('Less than 960');
}
else {
alert('More than 960');
}
nope, none of this will work. What you need is this!!!
Try this:
You might want to combine it with a resize event:
For R.J.:
I tried http://api.jquery.com/off/ with no success so I went with the eventFired flag.
I would suggest (jQuery needed) :
Added in CodePen : http://codepen.io/moabi/pen/QNRqpY?editors=0011
Then you can get easily window's width with the var : windowWidth and Height with : windowHeight
otherwise, get a js library : http://wicky.nillia.ms/enquire.js/
I know i'm late to answer this, but i hope it is of some help to anybody who have similar problem. It also works when page refreshes for any reason.