使用jQuery对高度变化执行函数



我想在div高度变化时运行一个函数,如果div高度增加,我想在body中添加一个类,如果高度减少到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');
  }
});

最新更新