ng-bootstrap collapse: How to apply animations?

后端 未结 4 1090
猫巷女王i
猫巷女王i 2021-02-19 09:39

I\'m using Collapse: https://ng-bootstrap.github.io/#/components/collapse

However, it does not animate; even not on the demo site. How should I implement this??

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 10:12

    Because they use "display: none" to hide and "display: block" to show element, you can't apply "transition" CSS property.

    So, force display block, manage height & opacity to toggle hide/show :

    .collapse, .collapse.in {
      display: block !important;
      transition: all .25s ease-in-out;
    }
    
    .collapse {
     opacity: 0;
     height: 0;
    }
    
    .collapse.in {
      opacity: 1;
      height: 100%;
    }
    

    With basic transition and opacity/height, it seem to be more smooth.

    You can make your own animation with keyframe and apply to .collapse.in to get better toggle hide/show experience.

    And then, if you use Angular 2 in your project, you can switch to ng2-bootstrap : http://valor-software.com/ng2-bootstrap/

提交回复
热议问题