javascript - if div does not contain this class then execute following -
at moment have few div resize functions work on different page width queries. these working fine, want wrap of these functions different window widths in conditional statement.basically want functions resize div "portfoliopod" if div not contain class pod expanded. please see code below , live example at
you can see on live example image being clipped due having height of how portfoliopod before expanding it
if ($( '.portfoliopod' ).not( ".podexpanded" )) { $(window).resize(function() { if ($(window).width() >= 1025) { var cw = $(".portfoliocontainer").width()/4; $('.portfoliopod').height(cw); } }); $(window).resize(function() { if ($(window).width() <= 1024) { var cw = $(".portfoliocontainer").width()/3; $('.portfoliopod').height(cw); } }); $(window).resize(function() { if ($(window).width() <= 767) { var cw = $(".portfoliocontainer").width()/2; $('.portfoliopod').height(cw); } }); $(window).resize(function() { if ($(window).width() <= 400) { var cw = $(".portfoliocontainer").width(); $('.portfoliopod').height(cw); } }); }
first, not need multiple resize
handlers. include them in same one.
second, use :not() selector
$(window).resize(function() { if ($(window).width() >= 1025) { var cw = $(".portfoliocontainer").width() / 4; $('.portfoliopod:not(.podexpanded)').height(cw); } if ($(window).width() <= 1024) { var cw = $(".portfoliocontainer").width() / 3; $('.portfoliopod:not(.podexpanded)').height(cw); } if ($(window).width() <= 767) { var cw = $(".portfoliocontainer").width() / 2; $('.portfoliopod:not(.podexpanded)').height(cw); } if ($(window).width() <= 400) { var cw = $(".portfoliocontainer").width(); $('.portfoliopod:not(.podexpanded)').height(cw); } });
Comments
Post a Comment