Reputation: 3145
having a weird bug atm. My window resize was working okay until I added an else if statement in the middle of the if and else statement. It caused my function to fire immediately to the if statement, even though the argument wasn't true. I have a feeling it's a dumb syntax error -- can anyone check this?
$(window).resize(function () {
var width = $(window).width;
var img = $('#e2-1 img');
if (1 < width < 1460) {
$(img).mapster('resize',650,null,null);
} else if (1461 < width < 1715) {
$(img).mapster('resize',750,null,null);
} else {
$(img).mapster('resize',930,null,null);
}
});
It's inside a (document).ready, if that matters. The .mapster is from an image map library I have that will resize my image map and all its coords by itself.
Thanks for any help! I'll make a fiddle if it's not just a dumb syntax error
Upvotes: 1
Views: 683
Reputation: 19093
Try re-writing
if (1 < width < 1460) {
as
if (width>1 && width<1460) {
I think it may be a precedence problem (1 < width evaluates to 1, which is less than 1460).
Upvotes: 2
Reputation: 4020
I think your if statements are wrong. The are not possible this way. You have to do
if((a < x) && (x < b))
$(window).resize(function () {
var width = $(window).width;
var img = $('#e2-1 img');
if ((1 < width) && (width < 1460)) {
$(img).mapster('resize',650,null,null);
} else if ((1461 < width) && (width < 1715)) {
$(img).mapster('resize',750,null,null);
} else {
$(img).mapster('resize',930,null,null);
}
});
Upvotes: 1