Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react animate on scroll

import { motion, useAnimation } from "framer-motion";
import { useInView } from "react-intersection-observer";
import { useEffect } from "react";

const boxVariant = {
  visible: { opacity: 1, scale: 1, transition: { duration: 0.5 } },
  hidden: { opacity: 0, scale: 0 }
};

const Box = ({ num }) => {

  const control = useAnimation();
  const [ref, inView] = useInView();

  useEffect(() => {
    if (inView) {
      control.start("visible");
    } else {
      control.start("hidden");
    }
  }, [control, inView]);

  return (
    <motion.div
      className="box"
      ref={ref}
      variants={boxVariant}
      initial="hidden"
      animate={control}
    >
      <h1>Box {num} </h1>
    </motion.div>
  );
};

export default function App() {
  return (
    <div className="App">
      <Box num={1} />
      <Box num={2} />
      <Box num={3} />
    </div>
  );
}
Comment

react animate on scroll

<ScrollAnimation animateIn='flipInY'
  animateOut='flipOutX'>
  <h1>
    animateOut
  </h1>
</ScrollAnimation>
Comment

react scroll animation

import "animate.css/animate.min.css";
Comment

PREVIOUS NEXT
Code Example
Javascript :: get array element by index javascript 
Javascript :: how to print a list in javascript 
Javascript :: react navbar responsive 
Javascript :: foreach await js 
Javascript :: java script 
Javascript :: npm font awesome angular 12 
Javascript :: jquerey dropdown button 
Javascript :: keyframe options 
Javascript :: js loop through array 
Javascript :: word table to json 
Javascript :: side effect, useEffect 
Javascript :: simple chat app 
Javascript :: pass props from child to parent 
Javascript :: service worker.js 
Javascript :: npm start browser 
Javascript :: call function 
Javascript :: push an item to array javascript 
Javascript :: react native modal 
Javascript :: javascript date timezone 
Javascript :: JavaScript ForEach This Argument 
Javascript :: javascript validator 
Javascript :: React useEffect() the side-effect runs after every rendering 
Javascript :: javascript list comprehension 
Javascript :: how to call a function javascript 
Javascript :: js repeat 
Javascript :: discord bot not responding to commands 
Javascript :: express multer 
Javascript :: js append html in div after 
Javascript :: what is palindrome 
Javascript :: radio button in reactive forms angular material 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =