I need to have some variable values change on window.resize().
I already found that you need to declare the variables outside the .resize function scope, i then try to change their values in the function .resize scope. But this doesn't seem to work.
var windowHeight = $(window).height();
var goPanel0, goPanel1, goPanel2, goPanel3;
goPanel0 = 0;
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
$(window).resize(function(){
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
//alert(goPanel3);
});
Thx,
I need to have some variable values change on window.resize().
I already found that you need to declare the variables outside the .resize function scope, i then try to change their values in the function .resize scope. But this doesn't seem to work.
var windowHeight = $(window).height();
var goPanel0, goPanel1, goPanel2, goPanel3;
goPanel0 = 0;
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
$(window).resize(function(){
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
//alert(goPanel3);
});
Thx,
Share Improve this question asked Jul 3, 2013 at 9:06 keviniuskevinius 4,6287 gold badges51 silver badges79 bronze badges 1-
Are you getting alert fired? in
resize()
– Dhaval Marthak Commented Jul 3, 2013 at 9:07
2 Answers
Reset to default 4$(window).resize(function(){
windowHeight = $(window).height(); // add this line
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
//alert(goPanel3);
});
value to variable windowHeight
was assigned out of .resize
scope, and in .resize
has previous value, but should have new value
simply you are not getting the new window height after resizing, so it will give you the same old value over and over, you have to re-assign the value (get the value) from inside the event's function to get the new one and use it.
$(window).resize(function(){
windowHeight = $(window).height(); // get new height after change
goPanel1 = windowHeight;
goPanel2 = windowHeight * 2;
goPanel3 = windowHeight * 3;
});