使用jQuery在高度变化时执行功能 [英] Execute function on height change using jQuery

查看:116
本文介绍了使用jQuery在高度变化时执行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在div高度变化时运行一个函数,如果div高度增加,我想向body添加一个类,如果高度降低到0,我想删除该类.

I wan to run a function on div height change, I want to add a class to body if div height increased and remove the class if height decrease to 0.

类似的东西:

$('.mydiv').change(function(){
    // add class to boy if height increase
})

推荐答案

$('.mydiv').resize(function() {
  if($(this).height() > 400){
    $('body').removeClass('normal height bigheight').addClass('bigheight');
  } else if ($(this).height() > 200){
    $('body').removeClass('normal height bigheight').addClass('height');
  } else if ($(this).height() > 0){
    $('body').removeClass('normal height bigheight').addClass('normal');
  } else {
    $('body').removeClass('normal height bigheight');
  }
});

这篇关于使用jQuery在高度变化时执行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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