jQuery - How to know if window is resizing in width/height or both?

前端 未结 2 922
Happy的楠姐
Happy的楠姐 2021-01-05 01:28

I have a little problem with window resizing using jQuery\'s function .resize(). I would like to know which dimension is getting bigger/smaller - width or height. I need thi

2条回答
  •  失恋的感觉
    2021-01-05 01:55

    By saving last window size values in variables.

    var h = $(window).height(), w = $(window).width();
    $(window).resize(function(){
    
        var nh = $(window).height(), nw = $(window).width();
         // compare the corresponding variables.
        h = nh; w = nw; // update h and w;
    });
    

提交回复
热议问题