用的react開發頁面,頁面切換的時候太快了,感覺效果不是很好,網上搜索了很多,發現這個簡單方便,效果也還可以,記錄一下
在父組件上添加 className=‘animate-route’
class Admin extends Component { constructor(props) { super(props); this.state = {}; } render() { return ( <div className='animate-route'> <GlobalStyle /> <Header /> <Content>{this.props.children}</Content> <Footer /> </div> ); } } export default Admin;
CSS添加如下代碼
.animate-route { animation-duration: 1s; animation-fill-mode: both; animation-name: fadeRoute; } @keyframes fadeRoute { from { opacity: 0; } to { opacity: 1; } }
刷新網頁看看把......