使用大小调整插件使用jQuery检测DIV的高度变化 [英] Detect height change of a DIV with jQuery using Resize Plugin

查看:163
本文介绍了使用大小调整插件使用jQuery检测DIV的高度变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此插件检查DIV的大小是否已更改:

I'm using this plugin to check if a size of a DIV is changed:

http://benalman.com/projects/jquery-resize-plugin/

它可以正常工作,但我不想只是检测DIV的大小,而是要检测DIV的高度是增加还是减少!

And it works just fine, but I don't want to just detect if a DIV is resized, I want to detect if the height of a DIV is increased or reduced!

如何实现?

谢谢

推荐答案

使用变量来跟踪高度:

var previousHeight = jQuery("#myDiv").height();

$("#myDiv").resize(function(e){ 
    // do something when element resizes 
    if(previousHeight < jQuery(this).height()){
        alert("now I'm bigger");
    }else{
        alert("Now I'm smaller");
    }
    //update previousHeight for next use
    previousHeight = jQuery(this).height();
});

这篇关于使用大小调整插件使用jQuery检测DIV的高度变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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