react頁面過渡動畫簡單實現

1. 在配置路由的外層父元素添加classNameless

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文件添加以下代碼:spa

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

@keyframes fadeRoute {
    from {
        opacity: 0;
    }
    to {
      opacity: 1;
    }
}
相關文章
相關標籤/搜索