react页面过渡动画简单实现


1. 在配置路由的外层父元素添加className

class App extends Component {
  render() {
    return (
      <div className='animate-route'>
        <Router>
          <Globalstyle />

          <Route exact path='/home' component={Home} />
          <Route exact path='/login' component={Login} />
        </Router>
      </div>
    );
  }
}

export default App;

 2. index.less文件添加如下代码:

.animate-route {
    animation-duration: 1s;
    animation-fill-mode: both;
    animation-name: fadeRoute;
}

@keyframes fadeRoute {
    from {
        opacity: 0;
    }
    to {
      opacity: 1;
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM