Created
September 30, 2010 13:50
-
-
Save jeremyckahn/604590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
jQuery Value Easer v0.1 | |
by Jeremy Kahn - jeremyckahn@gmail.com | |
Idea of animating a detached DOM element inspired from Ben Nadel: | |
http://www.bennadel.com/blog/2007-Using-jQuery-s-animate-Method-To-Power-Easing-Based-Iteration.htm | |
Sample usage: | |
$.valEase({ | |
from : -2, | |
to: 20, | |
duration : 1500, | |
step: function(num){ | |
console.log(num); | |
} | |
}); | |
*/ | |
(function( $ ){ | |
$.valEase = function(options) { | |
var dummy = $($('<div>')) | |
.css({ | |
'val' : options.from || 0 | |
}); | |
dummy.animate({ | |
'val': options.to || 0 | |
}, | |
$.extend(true, { | |
'easing': 'swing', | |
'duration': 1000 | |
}, | |
options, { | |
// This funtion cannot be overridden by the options. | |
'step': function(index){ | |
options.step(index); | |
} | |
}) | |
); | |
return this; | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment