Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created September 30, 2010 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyckahn/604590 to your computer and use it in GitHub Desktop.
Save jeremyckahn/604590 to your computer and use it in GitHub Desktop.
/*
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