Skip to content

Instantly share code, notes, and snippets.

@yelirekim
Created October 11, 2011 22:30
Show Gist options
  • Save yelirekim/1279659 to your computer and use it in GitHub Desktop.
Save yelirekim/1279659 to your computer and use it in GitHub Desktop.
dynamically generated animated setter
define([
'/dev/js/main.js',
'/dev/js/types.js',
rmod('common')],
function(main, types, common) {
return {
animated_setter: function(obj, property, getter, setter) {
return function(to, animated, easing, callback) {
if(common.is_false(animated)) {
return setter(to);
}
var from_obj = {};
from_obj[property] = getter();
var to_obj = {};
to_obj[property] = to;
var last = null;
$(from_obj).animate(to_obj, {
step:function(now, fx) {
if(last === null
|| (from_obj[property] > to_obj[property] && now < last)
|| (from_obj[property] < to_obj[property] && now > last)) {
last = now;
setter(now);
}
},
easing: easing,
duration: animated,
complete: function(fx) {
setter(to);
if(!common.is_false(callback)) {
callback();
}
}
});
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment