How to Remove Delay on Css3 Slide out transition which uses max-height transition

前端 未结 3 1828
醉话见心
醉话见心 2021-02-02 17:04

I\'m having an issue with a transition I\'m using to slide a panel in and out.

Please take a look at the following jsbin http://jsbin.com/uvejuj/1/

Notice that

3条回答
  •  礼貌的吻别
    2021-02-02 17:34

    I fixed it in my case by using normal transition for opening (from max-height 0px to max-height 500px) BUT by using an animation when closing, starting from max-height 50vh.

    This way the delay is not from shrinking from 5000px to the actual height of your content. The only delay that can appear now is if your content is less than 50% of your screen height, but that works buttersmooth in my cases.

    Here's my magic (scss format):

    .slide-open{
      max-height: 0;
      overflow: hidden;
      &:not(.open){
        animation-name: shrink;
        animation-duration: .3s;
      }
      &.open{
        max-height: 5000px;
        transition: max-height .9s ease-in-out;
      }
    }
    
    @keyframes shrink {
      0% { max-height: 50vh; }
      100% { max-height: 0; }
    }
    

提交回复
热议问题