Skip to content

Commit

Permalink
added updated throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 20, 2014
1 parent f7ea426 commit 6d9a6a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the [jquery.matchHeight.js demo](http://brm.io/jquery-match-height-demo).
### Features

- row aware, handles floating elements
- responsive, automatically updates on window resize
- responsive, automatically updates on window resize (can be throttled for performance)
- handles mixed `padding`, `margin`, `border` values (even if every element has them different)
- accounts for `box-sizing`
- handles images and other media (updates automatically after loading)
Expand Down Expand Up @@ -103,6 +103,12 @@ If you need to manually trigger an update of all currently set equal heights gro

Use the apply function directly if you wish to avoid the automatic update functionality.

$.fn.matchHeight._throttle = 80;

By default, the `_update` method is throttled to execute at a maximum rate of once every `80ms`.
Decreasing the above `_throttle` property will update your layout quicker, appearing smoother during resize, at the expense of performance.
If you experience lagging or freezing during resize, you should increase the `_throttle` property.

### Why not use CSS?

Making robust, responsive equal height columns for _arbitrary content_ is [difficult or impossible](http://filamentgroup.com/lab/setting_equal_heights_with_jquery/) to do with CSS alone (at least without hacks or trickery, in a backwards compatible way).
Expand Down
6 changes: 3 additions & 3 deletions jquery.matchHeight-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions jquery.matchHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@
*/

$.fn.matchHeight._groups = [];
$.fn.matchHeight._throttle = 80;

var previousResizeWidth = -1;
var previousResizeWidth = -1,
updateTimeout = -1;

$.fn.matchHeight._update = function(event) {

// prevent update if fired from a resize event
// where the viewport width hasn't actually changed
// fixes an event looping bug in IE8
Expand All @@ -156,9 +157,18 @@
previousResizeWidth = windowWidth;
}

$.each($.fn.matchHeight._groups, function() {
$.fn.matchHeight._apply(this.elements, this.byRow);
});
// throttle updates
if (updateTimeout === -1) {
updateTimeout = setTimeout(function() {

$.each($.fn.matchHeight._groups, function() {
$.fn.matchHeight._apply(this.elements, this.byRow);
});

updateTimeout = -1;

}, $.fn.matchHeight._throttle);
}
};

/*
Expand Down

0 comments on commit 6d9a6a7

Please sign in to comment.