React opacity animate组件进行不断闪烁

<html>
  <head>
    <title>Document</title>
    <script src="../react.js"></script>
    <script src="../react-dom.js"></script>
    <!-- //引用资源,JSX转HTML -->
    <script src="http://cdn.bootcss.com/babel-core/5.8.38/browser.min.js"></script>
  </head>

  <body>
    <div id="reactContainer"></div>

    <script type="text/babel"> //babel JSX => HTML
      const Hello = React.createClass({
        getInitialState: () => ({opacity: 1.0}),
        componentDidMount: function() {
          setInterval(function(){
            let opacity = this.state.opacity
            opacity = opacity < 0 ? 1 : opacity -= .05
            this.setState({opacity: opacity})
          }.bind(this), 100)
        },
        render: function() {
          return <div style={{opacity: this.state.opacity}}>Hello {this.props.name}</div>
        }
      })

      ReactDOM.render(
        <Hello name="wlh"/>,
        document.getElementById('reactContainer')
      )
    </script>
  </body>
</html>
阅读更多
个人分类: react
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭