当前位置:首页 > React

动画实现react图标

2026-01-26 19:11:01React

使用CSS动画实现React图标旋转

安装React Icons库(如未安装):

npm install react-icons

引入所需图标和CSS模块:

import { FaReact } from 'react-icons/fa';
import styles from './ReactIcon.module.css';

定义CSS动画:

/* ReactIcon.module.css */
.spin {
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

组件实现:

动画实现react图标

function AnimatedReactIcon() {
  return <FaReact className={styles.spin} size={48} color="#61DAFB" />;
}

使用Framer Motion实现高级动画

安装Framer Motion:

npm install framer-motion

实现弹性缩放动画:

import { motion } from "framer-motion";

function BouncingReactIcon() {
  return (
    <motion.div
      animate={{
        scale: [1, 1.2, 1],
        rotate: [0, 180, 360],
      }}
      transition={{
        duration: 2,
        repeat: Infinity,
        ease: "easeInOut"
      }}
    >
      <FaReact size={64} color="#61DAFB" />
    </motion.div>
  );
}

使用GSAP实现路径动画

安装GSAP:

动画实现react图标

npm install gsap

创建路径追踪动画:

import { useRef, useEffect } from 'react';
import { gsap } from 'gsap';

function PathAnimatedIcon() {
  const iconRef = useRef(null);

  useEffect(() => {
    gsap.to(iconRef.current, {
      rotation: 360,
      duration: 3,
      repeat: -1,
      ease: "power1.out",
      transformOrigin: "center"
    });
  }, []);

  return <FaReact ref={iconRef} size={72} color="#61DAFB" />;
}

SVG路径动画实现

自定义SVG动画组件:

function SvgReactIcon() {
  return (
    <svg
      width="100"
      height="100"
      viewBox="0 0 100 100"
      className={styles.pulse}
    >
      <circle cx="50" cy="50" r="20" fill="#61DAFB" />
      <g fill="none" stroke="#61DAFB" strokeWidth="2">
        <ellipse cx="50" cy="50" rx="35" ry="20" />
        <ellipse cx="50" cy="50" rx="35" ry="20" transform="rotate(60 50 50)" />
        <ellipse cx="50" cy="50" rx="35" ry="20" transform="rotate(120 50 50)" />
      </g>
    </svg>
  );
}

配套CSS:

.pulse {
  animation: pulse 1.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    transform: scale(0.9);
    opacity: 0.8;
  }
  to {
    transform: scale(1.1);
    opacity: 1;
  }
}

标签: 图标动画
分享给朋友:

相关文章

vue实现共享动画

vue实现共享动画

Vue 实现共享动画的方法 在 Vue 中实现共享动画(即多个元素间平滑过渡的动画效果)可以通过 Vue 的过渡系统和第三方库(如 GSAP)来实现。以下是几种常见方法: 使用 Vue 的 <…

css3 图标制作

css3 图标制作

CSS3 图标制作方法 使用伪元素和边框 通过 ::before 和 ::after 伪元素结合 CSS 边框属性可以创建简单图标。例如三角形图标: .triangle { width: 0;…

vue实现进入动画

vue实现进入动画

Vue 进入动画实现方法 使用 Vue 的过渡系统实现进入动画,主要通过 <transition> 或 <transition-group> 组件结合 CSS 或 JavaSc…

vue实现滑块动画

vue实现滑块动画

Vue 实现滑块动画的方法 使用 Vue Transition 组件 Vue 的 <transition> 组件可以轻松实现滑块动画效果。通过定义进入和离开的 CSS 过渡类,结合 v-i…

vue 实现动画效果

vue 实现动画效果

Vue 实现动画效果的方法 Vue 提供了多种方式实现动画效果,包括内置的过渡系统、第三方动画库以及 CSS 动画。以下是几种常见的方法: 使用 Vue 内置过渡系统 Vue 的 <trans…

vue实现页面动画切换

vue实现页面动画切换

使用 Vue 过渡组件实现动画切换 Vue 提供了内置的 <transition> 和 <transition-group> 组件,可以方便地实现页面或元素的动画切换效果。通过…