CSS how to make an element fade in and then fade out?

后端 未结 5 582
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 20:11

I can make an element with an opacity of zero fade in by changing its class to .elementToFadeInAndOut with the following css:

.elementToFadeInAndOut {
    op         


        
5条回答
  •  情书的邮戳
    2020-11-29 20:48

    I found this link to be useful: css-tricks fade-in fade-out css.

    Here's a summary of the csstricks post:

    CSS classes:

    .m-fadeOut {
      visibility: hidden;
      opacity: 0;
      transition: visibility 0s linear 300ms, opacity 300ms;
    }
    .m-fadeIn {
      visibility: visible;
      opacity: 1;
      transition: visibility 0s linear 0s, opacity 300ms;
    }
    

    In React:

    toggle(){
        if(true condition){
            this.setState({toggleClass: "m-fadeIn"});
        }else{
            this.setState({toggleClass: "m-fadeOut"});
        }
    }
    
    render(){
        return (
    Element to be toggled
    ) }

提交回复
热议问题