React animate transition between components

后端 未结 3 1843
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 11:48

I\'d like to animate between two components where the first component fades out and is removed from the DOM before the next component is added to the DOM and fades in. Other

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 12:14

    Another solution is to make the incoming and outgoing elements take up the same space, for example by having them both absolutely positioned:

    
    ...
    
    .container {
        position: relative;
    }
    .container > div {
        position: absolute;
    }
    

    http://jsfiddle.net/phepyezx/7/


    You can use transition-delay to wait until the leaving component disappears before making the entering component appear, e.g.:

    .fade-enter {
      opacity: 0.01;
    }
    .fade-enter.fade-enter-active {
      opacity: 1;
      transition: opacity 1s;
      transition-delay: 1s;
    }
    
    .fade-leave {
      opacity: 1;
    }
    .fade-leave.fade-leave-active {
      opacity: 0.01;
      transition: opacity 1s;
    }
    

提交回复
热议问题