Answer the question
In order to leave comments, you need to log in
How to make $(window).width() dynamically fired?
For example, there is a code:
if ($(window).width() < 480) {
$('.wow').addClass('slider');
}
else {
$('.wow').removeClass('slider');
}
Answer the question
In order to leave comments, you need to log in
$(function(){
$(window).resize(function(){
$('.wow').toggleClass('slider', $(window).width() < 480);
}).resize()
});
make a function out of this code and bind it to resize and load
I'll add to the answer above: move $('.wow') outside the resize callback:
var wow = $('.wow');
$(window).resize(function(){
if(...)
wow.addClass('slider');
else
wow.removeClass('slider');
});
var barrierWidth = 480;
var belowBar = currentWidth<480;
var wow = $('.wow');
function recalc(width){
if(width<barrierWidth && !belowBar)
wow.addClass('slider');
else if(width>barrierWidth && belowBar)
wow.removeClass('slider');
};
$(window).resize(function(){
recalc(width);
});
The suggested options worked, thanks. but the slider puzzled me)
it leaves 20 more classes inside my .wow list, that is, cleaning everything is long and wrong.
how to auto reload on some specific browser width? that is, they started to shrink the window, reached 480, caught a reboot, and so on? so that there is a constant reload on 480
(I just try for myself, on a real project, of course, doing this is nonsense)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question