Animation presets
Animation presets allow you to apply predefined animations to elements. You can specify presets using af-preset
attribute, or use af-preset-presetname
class, and they’ll be applied to the element when you animate it.
Create presets
Presets are defined inside AF.presets
object, and you can add as many as you want. To keep things simple, and don’t come up with crowded multi-level JSON objects, presets are made of properties similar to attributes you add in HTML and use 100% identical syntax. For example:
You can use any attributes you would normally use in HTML, including responsive suffixes, so if you wanted to alter duration in the example above for md
and below viewports, you could do it like this:
Apply presets
Use af-preset
attribute
You can apply presets to elements using af-preset
attribute. You can also use af-preset
together with other attributes — in this case, matching attributes you specify on the element itself will have precedence over preset attributes, e.g. this code
will use fadeIn
preset, and also animate y
property from 30
to 0
. Because duration
is defined both in the preset and on the element level, it will be 2
— because that’s what’s defined on the element level.
Use af-preset-name
class
AF will automatically add presets to elements that have af-preset-name
class. preset-name
is the name of the preset in kebab-case, so if you have presets named fadeIn
and downscale
, you can add it to an element like this: