0

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

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

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!

How this could be achieved?

Thanks

behz4d
  • 1,819
  • 5
  • 35
  • 59
  • Using the mentioned plugin, it's easy to detect a resize event, like: $("#unicorns").resize(function(e){ // do something when #unicorns element resizes }); – behz4d Aug 28 '12 at 07:59
  • That plugin seems a bit outdated, you should consider using jQuery UI resizable. It has all you could possibly need, including callback params giving you the new dimensions – Asciiom Aug 28 '12 at 07:59

1 Answers1

1

Use a variable to keep track of the height:

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();
});
Asciiom
  • 9,867
  • 7
  • 38
  • 57