CSS transition from `display: none` on class change?

后端 未结 4 1093
一生所求
一生所求 2020-12-14 14:41

I\'ve started using transitions to \"modernise\" the feel of a site. So far, :hover transitions are working great. Now I\'m wondering if it\'s possible to trigg

4条回答
  •  隐瞒了意图╮
    2020-12-14 15:07

    It does work when you remove the display properties.

    #myelem {
        opacity: 0;
        transition: opacity 0.4s ease-in;
        -ms-transition: opacity 0.4s ease-in;
        -moz-transition: opacity 0.4s ease-in;
        -webkit-transition: opacity 0.4s ease-in;
    }
    #myelem.show {
        opacity: 1;
        transition: opacity 0.4s ease-out;
        -ms-transition: opacity 0.4s ease-out;
        -moz-transition: opacity 0.4s ease-out;
        -webkit-transition: opacity 0.4s ease-out;
    }​
    

    JSFiddle.

    The reason for this is that only CSS properties with numbers can be transitioned. What do you think the "50% state" should be between "display: none;" and "display: block;"? Since that can't be calculated, you can't animate the display property.

提交回复
热议问题