The motion component has an initial prop:
<motion.div
initial={{ x: "100%" }}
animate={{ x: "calc(100vw - 50%)" }}
/>
while using useAnimate with useInView hook:
const [scope, animate] = useAnimate();
const isInView = useInView(scope, { once: true, amount: 0.8 });
useEffect(() => {
if (isInView) {
animate('.anim-up', { y: [100, 0] }, { duration: 1, delay: stagger(0.15) })
}
}, [isInView]);
all the elements jump from 0 to 100 at the first keyframe, how to set up an initial value?
When working with
useAnimate, assign the initial values in the CSS files itself. The value that you need your element to turn to must be then passed to the animate method. The propinitialisn't required when working withuseAnimate. Also, it is best you refer to your elements directly instead of using classNames (as in, "span"/"p"/"div" etc.)Here's an example of what your solution might look like (y moves from 100 to 0).
In the example above, the desired result can only be achieved if the
<span></span>s have atransform: translateY()of100. Also, please note that theuseEffectabove will only fire up if the state of the dependencyisInViewchanges (mentioning this as it seems to be a regular variable). Good luck!