Detect a window width change but not a height change

后端 未结 5 1866
傲寒
傲寒 2020-12-24 01:35

I\'m using the .resize() function to detect window re-size events, but this detects both height and width changes.

Is there any way to detect ju

5条回答
  •  余生分开走
    2020-12-24 01:50

    var width = $(window).width();
    $(window).on('resize', function() {
      if ($(this).width() !== width) {
        width = $(this).width();
        console.log(width);
      }
    });
    

提交回复
热议问题