I'm using bootstrap, and I'd like to add animation to a dropdown. I want to add an animation to it, slide down and back up when leaving it. How could I do this?
Things I tried:
Changing the Js drop down file like this:
How can I make Bootstrap's navigation dropdown slide smoothly up and down?
Here is a nice simple solution using
jQuery
that works nicely:The slide animation toggle occurs on clicking and it always slides back up on losing focus.
Alter the
300
value to anything you want, the lower the number the faster the animation.Edit:
This solution will only work for desktop views. It will need some further modification in order to display nicely for mobile.
I am using the code above but I have changed the delay effect by slideToggle.
It slides the dropdown on hover with animation.
This code works if you want to reveal dropdowns on hover.
I just changed the
.slideToggle
to.slideDown
&.slideUp
, and removed the(400)
timingI'm doing something like that but on hover instead of on click.. This is the code I'm using, you might be able to tweak it up a bit to get it to work on click
here is my solution for slide & fade effect:
If you update to Bootstrap 3 (BS3), they've exposed a lot of Javascript events that are nice to tie your desired functionality into. In BS3, this code will give all of your dropdown menus the animation effect you are looking for:
You can read about BS3 events here and specifically about the dropdown events here.