zoukankan      html  css  js  c++  java
  • React-router4 第八篇 ReactCSSTransitionGroup 动画转换

    https://reacttraining.com/react-router/web/example/animated-transitions

    动画转换这么高级,其实是又引入了一个组件,没什么特别,

    import React from 'react'
    import ReactCSSTransitionGroup from 'react-addons-css-transition-group'   // 就是他。。效果就是内容变化后,有一点点动画效果,
    import {
      BrowserRouter as Router,
      Route,
      Link,
      Redirect
    } from 'react-router-dom'
    
    /* you'll need this CSS somewhere  // 就是这些css样式
    .fade-enter {
      opacity: 0;
      z-index: 1;
    }
    
    .fade-enter.fade-enter-active {
      opacity: 1;
      transition: opacity 250ms ease-in;
    }
    */
    
    const AnimationExample = () => (
      <Router>
        <Route render={({ location }) => (
          <div style={styles.fill}>
            <Route exact path="/" render={() => (
              <Redirect to="/10/90/50"/>
            )}/>
    
            <ul style={styles.nav}>
              <NavLink to="/10/90/50">Red</NavLink>
              <NavLink to="/120/100/40">Green</NavLink>
              <NavLink to="/200/100/40">Blue</NavLink>
              <NavLink to="/310/100/50">Pink</NavLink>
            </ul>
    
            <div style={styles.content}>
              <ReactCSSTransitionGroup
                transitionName="fade"
                transitionEnterTimeout={300}  // 入场动画时间
                transitionLeaveTimeout={300}  // 出场动画时间
              >
                {/* no different than other usage of
                    ReactCSSTransitionGroup, just make
                    sure to pass `location` to `Route`
                    so it can match the old location
                    as it animates out
                */}
                <Route
                  location={location}
                  key={location.key}
                  path="/:h/:s/:l"
                  component={HSL}
                />
              </ReactCSSTransitionGroup>
            </div>
          </div>
        )}/>
      </Router>
    )
    
    const NavLink = (props) => (
      <li style={styles.navItem}>
        <Link {...props} style={{ color: 'inherit' }}/>
      </li>
    )
    
    const HSL = ({ match: { params } }) => (
      <div style={{
        ...styles.fill,
        ...styles.hsl,
        background: `hsl(${params.h}, ${params.s}%, ${params.l}%)`  // ES6的模板字符串
      }}>hsl({params.h}, {params.s}%, {params.l}%)</div>
    )
    
    const styles = {}
    
    styles.fill = {
      position: 'absolute',
      left: 0,
      right: 0,
      top: 0,
      bottom: 0
    }
    
    styles.content = {
      ...styles.fill,
      top: '40px',
      textAlign: 'center'
    }
    
    styles.nav = {
      padding: 0,
      margin: 0,
      position: 'absolute',
      top: 0,
      height: '40px',
       '100%',
      display: 'flex'
    }
    
    styles.navItem = {
      textAlign: 'center',
      flex: 1,
      listStyleType: 'none',
      padding: '10px'
    }
    
    styles.hsl  = {
      ...styles.fill,
      color: 'white',
      paddingTop: '20px',
      fontSize: '30px'
    }
    
    export default AnimationExample
    
  • 相关阅读:
    MVP模式与MVVM模式
    webpack的配置处理
    leetcode 287 Find the Duplicate Number
    leetcode 152 Maximum Product Subarray
    leetcode 76 Minimum Window Substring
    感知器算法初探
    leetcode 179 Largest Number
    leetcode 33 Search in Rotated Sorted Array
    leetcode 334 Increasing Triplet Subsequence
    朴素贝叶斯分类器初探
  • 原文地址:https://www.cnblogs.com/daowangzhizhu-pt/p/6674550.html
Copyright © 2011-2022 走看看