Skip to content
Advertisement

How can I add animation to Bootstrap dropdowns?

How can I add animation to the dropdown? I assume by modifying popperConfig, but how?

At the moment dropdown-menu has a generated inline style, e.g. position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate3d(0px, 40px, 0px);

Of course I can just add transition: translate .3s ease to it, but what if I want to change the direction or something more complex?

Advertisement

Answer

In the current example, the dm-example will be the dropdown menu that shows up.
HTML will not differ much from its Bootstrap5 examples:

JavaScript

For CSS animation rules handling:
#dm-example.show – describes initial styles for the block;
#dm-example.show .dropdown-item – describes initial styles for inner items;
dm-animation – is the animation on block;
item-animation – is the animation on items.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement