在react中要将页面跳转有动画

css 复制代码
// 页面切换过渡动画
.page {
  position: absolute;
  left: 15px;
  right: 15px;
}

// 页面切换过渡动画 --- 进入
.page-enter {
  opacity: 0;
  transform: translateY(100%);
}

// 页面切换过渡动画 --- 进入(被激活)
.page-enter-active {
  opacity: 1;
  // transform: scale(1);
  transform: translateY(0);
  transition: opacity 300ms, transform 300ms;
}

// 页面切换过渡动画 --- 离开
.page-exit {
  opacity: 1;
  transform: translateY(0%);
}

// 页面切换过渡动画 --- 离开(被激活)
.page-exit-active {
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 300ms, transform 300ms;
}

.tabsAnimation {
  position: absolute;
  animation: tabsIn .5s ease-in-out;
}

@keyframes tabsIn {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(0%);
  }
}
javascript 复制代码
 
import { CSSTransition, TransitionGroup } from 'react-transition-group';
<TransitionGroup>
              <CSSTransition
                key={window.location.pathname}
                timeout={300}
                classNames="page"
                unmountOnExit
              >
              <Routes >
                <Route path='' element={<Information />}></Route>
                <Route path='/Index' element={<Information />}></Route>
                <Route path='/Index/AerationControl' element={<AerationControl />}></Route>
                <Route path='/Index/AlarmManagement' element={<AlarmManagement/>}></Route>
                <Route path='/Index/SystemManagement' element={<SystemManagement/>}></Route>
              </Routes>
            </CSSTransition>
            </TransitionGroup>

npm install react-transition-group --save

react-transition-group 包住路由然后给样式 就可以达到页面跳转的时候样式动画

相关推荐
z***39622 分钟前
Plugin ‘org.springframework.bootspring-boot-maven-plugin‘ not found(已解决)
java·前端·maven
e***58233 分钟前
Nginx 配置前端后端服务
运维·前端·nginx
小奶包他干奶奶9 分钟前
Webpack学习——Plugin(插件)
前端·学习·webpack
张拭心12 分钟前
AI 从业者需要铭记的时刻:2023年6月30日
前端·ai编程
我叫张小白。24 分钟前
Vue3 Hooks:逻辑复用的解决方案
前端·javascript·vue.js·前端框架·vue
S***t71428 分钟前
前端物联网开发
前端·物联网
我叫张小白。35 分钟前
Vue3 Props 的使用:组件间数据传递的桥梁
前端·javascript·vue.js·vue3
r***869836 分钟前
Nginx解决前端跨域问题
运维·前端·nginx
广州华水科技43 分钟前
单北斗GNSS在桥梁变形监测中的关键应用与技术优势分析
前端
IT_陈寒44 分钟前
Python 3.12新特性实战:10个让你效率翻倍的代码优化技巧
前端·人工智能·后端