首页 > 其他 > 详细

react显示隐藏动画

时间:2019-07-22 10:54:14      阅读:126      评论:0      收藏:0      [点我收藏+]

通过className的true或者false控制元素显示或者隐藏。

App.js

import React, { Component } from ‘react‘;
import ‘./App.css‘
class App extends Component {
  constructor(props) {
    super(props);
    this.state = { 
        show:true,
        text:‘隐藏‘
     }
  }
  render() { 
    return ( 
      <div>
        <p className={this.state.show?‘show‘:‘hide‘}>文字</p>
        <button onClick={this.toggle}>{this.state.text}</button>
      </div>
     );
  }
  toggle =()=>{
    var show = this.state.show;
    var text = this.state.text;
    if(show){
      show =false
      text = ‘显示‘
    }else{
      show = true 
      text = ‘隐藏‘
    }
    this.setState({
      show:show,
      text:text
    })
  }
}
 
export default App;

 

App.css

.show{
  opacity: 1;
  transition: .5s all ease-in;
}

.hide{
  opacity: 0;
  transition: .5s all ease-in;
}

 

react显示隐藏动画

原文:https://www.cnblogs.com/luguankun/p/11223569.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!