Good evening, how do I get the script to work when the browser window is already initially changed?
$ (document) .ready (function () {
$ (window) .resize (function () {
if ($ (window) .width () & lt; = '995') {
$ ('# shelf'). show (10)
return this;}
else {
$ ('# shelf'). hide (10)
}
});
});
Answer 1, authority 100%
@Kp Houseoff , you only have changes by event .resize () . If you need to calculate when loading, then set exactly this event, namely .load () :
function windowSize () {
if ($ (window) .width () & lt; = '995') {
$ ('# shelf'). show (10);
} else {
$ ('# shelf'). hide (10);
}
}
$ (window) .load (windowSize); // while loading
$ (window) .resize (windowSize); // when resizing
// or two-in-one, instead of the last two lines:
$ (window) .on ('load resize', windowSize);
Answer 2
Check immediately. Resize () has not yet occurred in your code – condition is not checked.