In A Row

Get your ducks there!

home :: development :: js :: jthrottle

:: jThrottle - A jQuery Plugin to Throttle Big Loops

Uh oh!

Inspired by Oliver Steele's Sequentially Library and this post by Felix Geisendörfer, I created a very simple jQuery plugin.

It provides a drop-in replacement for each(), which performs the loop in iterations and pauses between each iteration. You'd only do this if you are iterating over a largish set and performing non-trivial operations. Basically, if the browser freezes, this is a decent solution as the call to setTimeout() allows the browsers UI thread to get a slice of the action and prevents spinning cursor syndrome.

If you wrote:

$('foo').each(function () { alert($(this).html()); });

Now you write:

$('foo').throttle(function () { alert($(this).html()); });

Or:

$('foo').throttle(
		function () { alert($(this).html()); },
		{per: 100, pause: 10});

Show Related Articles

Comments

Add a Comment:
 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Comment:
Please verify that you are human, or a good AI/OCR combo:
  Add to Technorati Favorites   Copyright 2008, Chris Moyer