Skip to content

Animation options

Animation targets allow you to specify element (or multiple elements) to animate using simple selector syntax. af-options lets you specify options for the animation.

Animation targets — af-target

By default, when you add any animation to the element, it’s presumed that animation will be applied to the element itself. But you can also use af-target attribute to specify which element(s) to animate. Use any valid CSS selector, including & symbol to refer to the element itself, combined with other valid CSS selectors, like & > div or .box or & ul li. Or specify entirely different element to animate. Some examples:

Target valueDescription
&(Default, can be omitted)Animates the element itself
& > divAnimates all direct child div elements inside the element
.boxAnimates all elements with class box
& ul liAnimates all li elements inside ul elements inside the element
#my-idAnimates element with id my-id

This can be useful for example when you want to create a staggered animation, or when you want to assign similar animations to a set of elements defined with some CSS class.

Animation options — af-options

af-options provides an easy way to set animation options for any type of animation.

Animation options is the best place to provide options like duration, delay, stagger, easing, yoyo etc. Depending on the animation type, they’ll be added to: from animation parameters if you only have from animation, to animation parameters if you have only to or from and to animations, or as entire animation options when you have keyframes animation. You can also provide all those options inside af-from or af-to attributes directly — but it’s there to have a more unified way to set them, that’s separate from the animation itself.

af-options is responsive, so you can provide different options for different breakpoints by adding breakpoint suffix to the attribute name. E.g. af-options-md will apply different options to viewports with md breakpoint.

Some of the most commonly used options are:

OptionExample valueDescription
delaydelay: 0.5Delay before the animation starts (in seconds)
durationduration: 0.5Duration of the animation in seconds
easeease: power2.inOutEasing function to use
repeatrepeat: 2Number of times to repeat the animation
repeatDelayrepeatDelay: 0.5Delay between repeats (in seconds)
staggerstagger: 0.5Delay between animations (in seconds)
startAtstartAt: { x: 120 }Starting values for animated properties
yoyoyoyo: trueReverses animation direction