diff options
author | Matt Banks <mjbanks@gmail.com> | 2015-07-17 10:56:38 -0400 |
---|---|---|
committer | Matt Banks <mjbanks@gmail.com> | 2015-07-17 10:56:38 -0400 |
commit | 69d5afef56d42f30eb4804e9e8dd0a213b61f56c (patch) | |
tree | f815eaca5e0b4bb61ec3283ceb69dbd5d0b24756 | |
parent | 23aacc7734b8881ace02f226fdfa49d12fdc20c2 (diff) | |
parent | c539e792cd0ad16bb1c60fe25e507e1955cff197 (diff) | |
download | jQuery.equalHeights-69d5afef56d42f30eb4804e9e8dd0a213b61f56c.zip jQuery.equalHeights-69d5afef56d42f30eb4804e9e8dd0a213b61f56c.tar.gz jQuery.equalHeights-69d5afef56d42f30eb4804e9e8dd0a213b61f56c.tar.bz2 |
Merge pull request #13 from DavidMoritz/patch-1
Add option "wait"
-rw-r--r-- | jquery.equalheights.js | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/jquery.equalheights.js b/jquery.equalheights.js index d05c700..94f0c9a 100644 --- a/jquery.equalheights.js +++ b/jquery.equalheights.js @@ -10,17 +10,29 @@ */ (function($) { - $.fn.equalHeights = function() { + $.fn.equalHeights = function(options) { var maxHeight = 0, - $this = $(this); + $this = $(this), + equalHeightsFn = function() { + var height = $(this).innerHeight(); + + if ( height > maxHeight ) { maxHeight = height; } + }; + options = options || {}; - $this.each( function() { - var height = $(this).innerHeight(); + $this.each(equalHeightsFn); - if ( height > maxHeight ) { maxHeight = height; } - }); - - return $this.css('height', maxHeight); + if(options.wait) { + var loop = setInterval(function() { + if(maxHeight > 0) { + clearInterval(loop); + return $this.css('height', maxHeight); + } + $this.each(equalHeightsFn); + }, 100); + } else { + return $this.css('height', maxHeight); + } }; // auto-initialize plugin |