Change variable values on window.resize

后端 未结 2 460
执念已碎
执念已碎 2020-12-22 07:38

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

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 08:03

    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;
    });
    

提交回复
热议问题