10

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?

4
  • 3
    The animation isn't yet supported by ngx-bootstrap
    – IlyaSurmay
    Commented Mar 26, 2018 at 9:07
  • @IlyaSurmay Is there any work-arround for the moment, thanks ? Commented Mar 26, 2018 at 9:16
  • 1
    I'm afraid there is no workaround for now. Adding animation is in our plans github.com/valor-software/ngx-bootstrap/issues/801
    – IlyaSurmay
    Commented Mar 26, 2018 at 9:30
  • 1
    Anyone finds this now they do have a `[isAnimated]="true" option now in the docs.
    – Mark
    Commented Oct 7, 2020 at 17:09

4 Answers 4

9

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*/
}
2
  • 2
    With a max-height that is so high, your animation will be very fast (it has to traverse 9999px in .5 seconds). Commented Jan 7, 2019 at 10:10
  • Use max-height: 100vh; if your elements are not larger than the viewport height;
    – Mosrainis
    Commented Aug 7, 2021 at 7:50
4

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;
}
2

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);
}
2

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"> ...

Not the answer you're looking for? Browse other questions tagged or ask your own question.