react路由动画跳转,猛练自然强

文章介绍了如何在React项目中使用animate.css库来创建路由跳转时的动画效果。首先,通过npm或yarn安装animate.css,然后在组件中引入库,给需要动画的元素添加特定的className。接着,自定义CSS样式以设置动画效果的持续时间和延迟时间。最后,通过绑定className到组件的根节点,实现在路由切换时触发动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

react路由动画跳转

1.先在react项目中下载一个css第三方库。用npm或者yarn

// 第三方库下载
 npm install animate.css --save
 yarn add animate.css

2.在react组件中引用这个css库

// 引用库
import 'animate.css';

3 .引用到组件中

// 引用到组件中
import React,{useEffect,useState} from 'react'
import 'animate.css';

4.因为react只有一个根节点,在最外层的盒子给一个classname名称

<div class="animate__animated animate__bounce">An animated element</div>

5.创建一个css文件,引用到组件

.my-element {
    display: inline-block;
    margin: 0 0.5rem;
  
    animation: bounce; /* referring directly to the animation's @keyframe declaration */
    animation-duration: 2s; /* don't forget to set a duration! */
}
/* This only changes this particular animation duration */
.animate__animated.animate__bounce {
    --animate-duration: 2s;
  }
  
  /* This changes all the animations globally */
  :root {
    --animate-duration: 800ms;
    --animate-delay: 0.9s;
}

6 .css动画网址 链接: 点击到https://animate.style/
7.总结:
下载 第三方库 引用
创建 css文件,引用
那个组件想要实现跳转动画功能,就在那个组件的根节点绑定classname属性即可
在跳转的时候即可实现

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值