DIV宽度更改时如何动态更改类? [英] How to dynamically change classes when DIV width changes?

查看:86
本文介绍了DIV宽度更改时如何动态更改类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在更改窗口大小时使用Jquery更改类,但是我需要基于DIV的宽度并在DIV的宽度更改时动态更改.

I know how to change classes with Jquery when the window size is changed, but I need it to be based on the width of a DIV and change dynamically when the DIV's width changes.

$(window).resize(function() {

   var wrapWidth = $('.info-wrap').width();

    if (wrapWidth >= 500) {

      $('#partOne').addClass('big');
      $('#partTwo').addClass('big');

    } else {

      $('#partOne').removeClass('big');
      $('#partTwo').removeClass('big');
    }
});

这在窗口大小更改时有效.但是,我可以使用$(window).resize的输入来获取DIV随宽度变化的宽度吗?

This works when the window size changes. But, what can I use insead of $(window).resize to get the width of the DIV as it changes?

推荐答案

我认为您需要为JQuery使用插件,例如

I think you'll need to use a plugin for JQuery, such Ben Alman's plugin.

我不认为有什么东西可以检测div何时调整大小,只有窗口即可.

I don't think there exists something that detects when a div gets resize, only the window.

这篇关于DIV宽度更改时如何动态更改类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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