Если вы хотите что-то более подробно вы можете собрать удивительный Animate.css (крест -browser-библиотека анимации CSS), немного jquery и, конечно же, Twitter Boostrap.
В вашем заголовке:
<head>
...
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
</head>
В вашем теле, где вы хотите создать выпадающее меню:
<div class="dropdown" data-animation="slideInDown,slideOutUp,600">
<button type="button" class="btn btn-primary" data-toggle="dropdown">Click to toggle animated dropdown <i class="caret"></i></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
Обратите внимание на атрибут данных анимации в разметке, вы должны предоставить 3 параметра, анимация, аут-анимация и продолжительность.
Вы можете играть, если хотите, с помощью other animations.
В футере (или там, где вы предоставляете свои скрипты):
<script src="js/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
$(function() {
var $in, $out, $duration;
$('.dropdown')
.on('shown.bs.dropdown',
function (e) {
if ($(this).attr('data-animation')) {
let $animations = [];
const $animation = $(this).data('animation');
$animations = $animation.split(',');
$in = 'animated ' + $animations[0];
$out = 'animated ' + $animations[1];
$duration = '';
if (!$animations[2]) {
$duration = 500;
} else {
$duration = $animations[2];
}
$(this).find('.dropdown-menu').removeClass($out);
$(this).find('.dropdown-menu').addClass($in);
}
});
$('.dropdown')
.on('hide.bs.dropdown',
function (e) {
if ($(this).attr('data-animation')) {
e.preventDefault();
const $this = $(this);
const $targetControl = $this.find('.dropdown-menu');
$targetControl.addClass($out);
setTimeout(function() {
$this.removeClass('open');
},
$duration);
}
});
})
</script>
Надеется, что это помогает!
Нужен полный образец?
$(function() {
var $in, $out, $duration;
$('.dropdown')
.on('shown.bs.dropdown',
function (e) {
if ($(this).attr('data-animation')) {
let $animations = [];
const $animation = $(this).data('animation');
$animations = $animation.split(',');
$in = 'animated ' + $animations[0];
$out = 'animated ' + $animations[1];
$duration = '';
if (!$animations[2]) {
$duration = 500;
} else {
$duration = $animations[2];
}
$(this).find('.dropdown-menu').removeClass($out);
$(this).find('.dropdown-menu').addClass($in);
}
});
$('.dropdown')
.on('hide.bs.dropdown',
function (e) {
if ($(this).attr('data-animation')) {
e.preventDefault();
const $this = $(this);
const $targetControl = $this.find('.dropdown-menu');
$targetControl.addClass($out);
setTimeout(function() {
$this.removeClass('open');
},
$duration);
}
});
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
<div class="dropdown" data-animation="slideInDown,slideOutUp,600">
<button type="button" class="btn btn-primary" data-toggle="dropdown">Click to toggle animated dropdown <i class="caret"></i></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
Нам нужно больше информации ... Вы можете расширить свой пример, чтобы включить соответствующий код? – mhatch
@mhatch Done. Обновлен код в вопросе. – Somename