1.0.0 • Published 9 years ago
snap-animation-states v1.0.0
snap-animation-states
A Snap.svg plugin that lets you load and animate svgs using a simple schema.
Installation
Include JS
Include Snap.svg 0.4.1 and snap-animation-states.js in the footer. No JQuery needed.
<script type="text/javascript" src="js/snap.svg.js"></script>
<script type="text/javascript" src="js/snap-animation-states.js"></script>Set HTML
Your SVGs need a container element. You just need to add whatever class you're calling your svg with to the element that will contain it.
<i class="icon-hamburger"></i><br>
<i class="my-svg-selector"></i> Call the plugin
It's as simple as calling the plugin with the correct schema.
(function() {
SnapStates({ ...schema... })
})();Schema
selector: stringcss selector - ex: ".icon-hamburger"svg: stringsvg string or svg file referenceeasing: string"linear", "easein", "easeout", "easeinout", "backin", "backout", "bounce", "elastic"transitionTime: intTransition time is applied to each transform. A state with 3 transforms one after the other and a transitionTime of 500 ms will take a total of 1500 ms to finishinitState: stringSet initState equal to the state you want to run when the plugin is called.states: objContains the states and transforms to be performed. Each state contains an array of transforms. -key: state nameprop: array of transform objectsid: int/string/arrThe id should be unique to its state. If you want the transform to start after a timeout, the id takes an array: id, timeout:intwaitFor: int/string/arrSet the waitFor property to the id of a transform that it should follow. For a timeout, waitFor takes an array: id, timeout: intelement: stringTakes the css selector of the element that the transform is affecting.x: intTakes an x coordinate relative to the elements starting positiony: intTakes a y coordinate relative to the elements starting positionr: int/array- r:180 rotates the element 180 degrees around its center - r:180, 30, 30 rotates the element 180 degrees around the coordinates 30, 30 on the svg canvass: int/array- s:0.5 scales the element down to half its size. - s:0.5, 1 scales the element down to half its size horizontally without affecting its vertical size. - s:0.5, 0.5, 30, 30 scales the element down to half its size around the coordinates 30, 30 on the svg canvasattr: objAffect any svg attributepath: stringRepresented by the "d" attribute in an svg. Learn more about paths.drawPath: int/obj- int: percentage of path to draw. 0 is no path and 100 is the full path length - obj: {min: minPath max: maxPath} Randomize your path length using min and maxtransitionTime: int/obj- int: transition time to override the base transition time - obj: {min: minTime max: maxTime} Randomize the transitionTime with a min and maxeasing: stringsame easing options as previously shown. Useful if you have several types of easing you want to display from transform to transform *repeat: objWill repeat the entire state from the point the repeat is called -loop :boolset an infinite loop -loopDuration :intend loop after a time -times: intloop the animation x timesevents:array of objects-event: stringworks with any javascript event -state: string/arraystring: string matches name of state you want to run when the event happens array: used for toggle events. "state1", "state2" can be toggled when the event happens -selector: stringa css selector used to indicate where to watch for the event - ex: an svg inside an anchor tag. The anchor tag will receive the selector so that when the anchor is clicked the svg animation runs.