Created
October 11, 2011 22:30
-
-
Save yelirekim/1279659 to your computer and use it in GitHub Desktop.
dynamically generated animated setter
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
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