Detect a window width change but not a height change

后端 未结 5 1854
傲寒
傲寒 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 02:08

    One can also use this tiny jQuery plugin for this: https://github.com/adjohnson916/jquery-resize-dimension

    Keeps your own code more readable:

    ResizeDimension.bind('width');
    $(window).on('resize-width', function () {
      console.log('resize-width event');
    });
    

    or just:

    $(window).resizeDimension('width', function () {
      console.log('resize-width event');
    });
    

提交回复
热议问题