Created
August 25, 2014 11:21
-
-
Save cfenzo/b5f6cb2fb075bca44562 to your computer and use it in GitHub Desktop.
A utility-function for adding squences in velocity.js, was the base of the sequences-functionality that is now present in velocity.js
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
/* | |
animations is declared like this: | |
- simple (one or more rules, in one duration): | |
'name':{style:value,style2:value} | |
- complex (one or more rules, split duration): | |
'name':[ | |
[{style:value,style2:value},'unitless percentage of duration'||{options}], | |
[{style:value,style2:value},'unitless percentage of duration'||{options}] | |
] | |
*/ | |
jQuery.velocity.add_sequence = function(name,calls){ | |
if(!Array.isArray(calls)){ | |
calls = [[calls,100]]; | |
} | |
jQuery.velocity.Sequences[name] = function(el, options){ | |
var options = options || {}, | |
duration = options.duration || 1000, | |
parts_count = calls.length; | |
calls.forEach(function(call,i){ | |
var opts = (/(\d)$/i.test(call[1])) ? {duration:call[1]} : call[1]; // nice with shorthand duration | |
if(i+1===parts_count) opts.complete = options.complete; | |
opts.duration = (duration/100)*opts.duration; | |
jQuery.velocity.animate(el,call[0],opts); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment