In the ground since Fri Oct 01 2021
Last watered inFri Oct 01 2021
animate() from framer-motion X animate() from useAnimate()
When we import animate() from framer-motion, all elements that iteract with it will be under its scope and will share it! So, be aware of side effects like the same animation being triggered for another element other than the one you expect
animate() from useAnimate() will be scoped to the component/hook where you've instantiated useAnimate(). It won't interfere with other elements
When animating an SVG path, the animate() function will not animate the pathLengh. It will change its value abruptly.
We need to add an initial value:
Framer Motion can animate transform props, but will clash with CSS transform rules applied to the element you're animating.
Let's say you're centralizing an element with transform: translate(-50%, -50%). If you animate the x property, it will work, but when the animations ends, Framer will apply transform: none as inline style therefore overriding the transform: translate(-50%, -50%) appplied via any CSS Selector
Remove the styles you've applied via CSS and apply them via Framer Motion.
We can use CSS calc() inside a string:
It' nice to keep in mind to not mix SVG attributes that will be animated with CSS classes that will be animated. This can lead to unexpected behavior.
Example
We have an SVG that will be animated on hover. We'll change its fill. We need to set fill in two places:
This is how it would get confused:
The result of this example is:
Commit https://github.com/mariobrusarosco/portfolio/pull/15/commits/4a27f6a52796450db9fbb9ecd29c18f8d60cefef#diff-acc19abade6e78ac892adea5efaf181ab9136b6f88aeb62033ed51aed9ad7b89