Reputation: 2415
AT the moment I have a few div resize functions that work on different page width queries. These are working fine, however I want to wrap all of these functions for the different window widths in a conditional statement.Basically I only want the functions to resize the div "portfoliopod" if the div does not contain the class pod expanded. Please see my code below and a live example at
You can see on the live example that the image is being clipped due to having the height of how the portfoliopod was 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);
}
});
}
Upvotes: 0
Views: 88
Reputation: 30557
First, you do not need multiple resize
handlers. Include them in the same one.
Second, use the :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);
}
});
Upvotes: 2
Reputation: 17661
You may use this selector:
$(".portfoliopod:not(.podexpanded)")
It will select all elements with the class portfoliopod
, but only those that do not have the class podexpanded
.
Upvotes: 5