检测窗户的宽度变化但不检测高度变化 [英] Detect a window width change but not a height change

查看:67
本文介绍了检测窗户的宽度变化但不检测高度变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.resize()函数来检测窗口调整大小的事件,但这会检测到高度和宽度的变化.

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?

推荐答案

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

这篇关于检测窗户的宽度变化但不检测高度变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆