Slide down animation from display:none to display:block?

前端 未结 5 1217
无人共我
无人共我 2020-12-14 07:47

Is there a way to animate display:none to display:block using CSS so that the hidden div slides down instead of abruptly appearing, or should I go about this a different way

5条回答
  •  北海茫月
    2020-12-14 08:13

    Yes, there is a way: http://jsfiddle.net/6C42Q/12/

    By using CSS3 transitions, and manipulate height, rather than display property:

    .hidden {
        height: 0px;
        -webkit-transition: height 0.5s linear;
           -moz-transition: height 0.5s linear;
            -ms-transition: height 0.5s linear;
             -o-transition: height 0.5s linear;
                transition: height 0.5s linear;
    }
    
    .hidden.open {
         height: 200px;
         -webkit-transition: height 0.5s linear;
            -moz-transition: height 0.5s linear;
             -ms-transition: height 0.5s linear;
              -o-transition: height 0.5s linear;
                 transition: height 0.5s linear;
    }
    

    More here: Slide down div on click Pure CSS?

提交回复
热议问题