Abdennacer Lachiheb
Abdennacer Lachiheb

Reputation: 4888

Angular ngx-bootstrap collapse is not animated

I'm using angular 5 and ngx-bootstrap, so when I tried to add a collpase, by following the collapse docs , I got a working example but without animation ( the collapsed dissepears and appears instantly without effects).

So is there a way to show the animation?

Upvotes: 10

Views: 10422

Answers (4)

Stanislav
Stanislav

Reputation: 4589

In my case I just added [isAnimated]="true" as it's shown in https://valor-software.com/ngx-bootstrap/#/collapse#animated

<div id="collapseBasic" [collapse]="isCollapsed" [isAnimated]="true"> ...

Upvotes: 2

Parth Developer
Parth Developer

Reputation: 1887

The following answer is for ngb versionn 5.x.x

If you want to animate the [ngbCollapse] directive

use the code in your component's scss file and modify the following scss as per your requirement:

.collapse {
  transition: transform .35s, opacity .35s, max-height .9s ease-out;
  opacity: 0;
  max-height: 0;
  // transform: translateY(100%);
  display: block !important;

  &.show {
    opacity: 1;
    max-height: 600px;
    // transform: translateY(0);
  }
}

or if you are using CSS : use the below-mentioned code:

.collapse {
  transition: transform .35s, opacity .35s, max-height .9s ease-out;
  opacity: 0;
  max-height: 0;
  // transform: translateY(100%);
  display: block !important;

}

.collapse.show {
  opacity: 1;
  max-height: 600px;
  // transform: translateY(0);
}

Upvotes: 2

Oleg Polezky
Oleg Polezky

Reputation: 1132

This could be a solution for the whole project.

.collapse {
    transition: all 0.3s ease-out;
    display: block !important;
    overflow: hidden !important;
    max-height: 0;
}

.collapse.in {
    transition: all 0.5s ease-in;
    max-height: 9999px; /*any number which is lager than a height of any of your elements*/
}

Upvotes: 9

Irfan
Irfan

Reputation: 77

I had same issue and I resolve it by some css trick. It worked for me. I'm hoping that it would work for you. I happens because ngx-bootstrap doesn't use the ".collapsing" class so I done some changes in my code.

#your_nav{
    display: block !important;
    max-height: 1px !important;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    -webkit-transition: all 0.3s ease-in-out;
    -ms-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}
#your_nav.show{
    max-height: 230px !important;
}

Upvotes: 4

Related Questions