summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--example/example.html15
-rw-r--r--jquery.equalheights.js20
2 files changed, 26 insertions, 9 deletions
diff --git a/example/example.html b/example/example.html
index 216137e..1351b5d 100644
--- a/example/example.html
+++ b/example/example.html
@@ -46,8 +46,21 @@
</div>
</div>
+ <div data-heights="equal" data-targets="div" class="clearfix">
+ <h3>Using equal heights with <pre>data-heights="equal" data-target="div"</pre></h3>
+ <div class="column1">
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+ </div>
+ <div class="column2">
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
+ </div>
+ <div class="column3">
+ <p>Lorem ipsum dolor sit amet</p>
+ </div>
+ </div>
+
<script src="jquery-1.7.2.min.js"></script>
- <script src="../jquery.equalheights.min.js"></script>
+ <script src="../jquery.equalheights.js"></script>
<script>
$('#equalheight div').equalHeights();
</script>
diff --git a/jquery.equalheights.js b/jquery.equalheights.js
index f21303c..560fd64 100644
--- a/jquery.equalheights.js
+++ b/jquery.equalheights.js
@@ -10,17 +10,21 @@
*/
(function($) {
- $.fn.equalHeights = function() {
- var maxHeight = 0,
+ $.fn.equalHeights = function() {
+ var maxHeight = 0,
$this = $(this);
- $this.each( function() {
- var height = $(this).innerHeight();
+ $this.each( function() {
+ var height = $(this).innerHeight();
- if ( height > maxHeight ) { maxHeight = height; }
- });
+ if ( height > maxHeight ) { maxHeight = height; }
+ });
- return $this.height(maxHeight);
- };
+ return $this.height(maxHeight);
+ };
+
+ // auto-initialize plugin
+ var target = $('[data-heights="equal"]').attr('data-targets'), init = '[data-heights="equal"] ' + target;
+ $(init).equalHeights();
})(jQuery);