I have the following code and I try to add a down effect to the dropdown so that when it is clicked it slides down slowly.
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
The code I have tried to use is the following:
$('.dropdown').on('show.bs.dropdown', function() {
$(this).find('.dropdown-menu').first().stop(true, true).slideDown();
});
$('.dropdown').on('hide.bs.dropdown', function() {
$(this).find('.dropdown-menu').first().stop(true, true).slideUp();
});
As you can see the code I simply apply a show animation to the hide to show and hide my dropdown but it doesn't work does anyone have any idea how to solve this type of problem?
Also try applying the following code:
<script type="text/javascript">
$( document.body ).click(function () {
if ( $( "div:dropdown-menu" ).is( ":hidden" ) ) {
$( ".dropdown-menu" ).slideDown( "slow" );
} else {
$( ".dropdown-menu" ).hide();
}
});
</script>
NOTE: I added all bootstrap and jquery links.
With
slideToggle()
works fine. I leave you an example: