Created
October 22, 2012 12:44
-
-
Save kopiro/3931332 to your computer and use it in GitHub Desktop.
Wrapper for jQuery.animate in CSS (if supported)
This file contains hidden or 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
| $.fn.extend({ | |
| cssanimate : function(css_values, anim_time, anim_method, callback) | |
| { | |
| var $this = $(this); | |
| if (!Modernizr.csstransitions) | |
| { | |
| $this.animate(css_values, anim_time, anim_method, callback); | |
| return; | |
| } | |
| if (!css_values) return; | |
| if (callback) setTimeout(callback, anim_time); | |
| var CSSEasing = | |
| { | |
| 'easeOutExpo' : 'cubic-bezier(0.190, 1.000, 0.220, 1.000)', | |
| 'easeInExpo' : 'cubic-bezier(0.950, 0.050, 0.795, 0.035)', | |
| 'easeInOutExpo' : 'cubic-bezier(1.000, 0.000, 0.000, 1.000)' | |
| }; | |
| anim_time = anim_time || 0; | |
| anim_method = anim_method || 'linear'; | |
| var anim_method_css; | |
| if (CSSEasing[anim_method]) anim_method_css = CSSEasing[anim_method]; | |
| else anim_method_css = anim_method.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }); | |
| var transition_prop = Modernizr.prefixed('transition').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }); | |
| var transition_val = anim_time+"ms "+anim_method_css; | |
| $this.css(transition_prop, transition_val); | |
| $this.css(css_values); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment