I have created a dropdown using ngx bootstrap. In the dropdown I want to add a custom animation. I have created a animation using angular's animation library and added it in the dropdown. But it is not working.
Question - how I can add the custom animation in the bootstrap dropdown?
This is what i have done -
Component HTML -
<div class="btn-group" dropdown>
<button id="button-basic" dropdownToggle type="button" class="btn btn-primary dropdown-toggle" aria-
controls="dropdown-basic">
Button dropdown <span class="caret"></span>
</button>
<ul id="dropdown-basic" *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="button-basic"
[@dropdownAnimation]>
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Component ts -
animations: [
trigger("dropdownAnimation", [
transition(":enter", [
style({
transform: "translate(0, -40px)",
opacity: 0,
visibility: "hidden",
}),
animate(
"400ms ease-in-out",
style({ transform: "translate(0, 0)", opacity: 1, visibility: "visible" })
),
]),
transition(":leave", [
style({ transform: "translate(0, 0)", opacity: 1, visibility: "visible" }),
animate(
"400ms ease-in-out",
style({
transform: "translate(0, -40px)",
opacity: 0,
visibility: "hidden",
})
),
]),
])
]
Add BsDropdownModule
to app.module.ts
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
@NgModule({
imports: [BsDropdownModule.forRoot(),...]
})
export class AppModule(){}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.