jqueryresponsive-designresizejquery-events

Detect a window width change but not a height change


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 just a width change and not a height change?


Solution

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