Bootstrap 多级下拉滑动效果?
Bootstrap multilevel dropdown slide effect?
我在我制作的 Bootstrap 项目中有一个多级下拉菜单。我需要它,这样下拉菜单才会滑动。我该如何实现?
我已经完成了以下代码,但我需要添加到其中。以下是代码的作用:
- 如果您单击其下拉开关,它会打开和关闭 特定 下拉菜单。
- 如果您在下拉菜单外部单击,但在其父级内部单击,则只有子下拉菜单会关闭;如果您在父项外部单击,父项将关闭,依此类推。
- 如果您单击子下拉列表的下拉开关,它只会影响该下拉列表及其子项,不会其父项。
我已阅读此答案以尝试将其与我当前的解决方案一起使用,但我不知道如何使其正常工作:
我相信它有更多的规格,但你明白了。这也是我制作的一个 jsfiddle:http://jsfiddle.net/hhb9u7db/
例如,我将 Collections link 设为下拉菜单,将 T 恤 设为另一个下拉菜单。我希望这一切都像我现在的工作方式一样工作,只是它会滑动。
$(function() {
$('.dropdown').on({
"click": function(event) {
if ($(event.target).closest('.dropdown-toggle').length && $(this).parents('.dropdown').length === ($(event.target).parents('.dropdown').length - 1)) {
$(this).data('closable', true);
} else {
$(this).data('closable', false);
}
},
"hide.bs.dropdown": function(event) {
hide = $(this).data('closable');
$(this).data('closable', true);
return hide;
}
});
});
你的 fiddle 对我来说不是很清楚。您的导航栏没有 .navbar
class 并且您的导航菜单没有 .navbar-nav
.
您可以尝试添加如下所示的 CSS 代码:
.dropdown-menu,
.open > .dropdown-menu,
.dropdown-menu,
.open > .dropdown-menu .dropdown-menu {
display: block;
max-height: 0;
overflow-y:hidden;
visibility: hidden;
-webkit-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-moz-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-o-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu,
.nav-pills > li.open > .dropdown-menu,
.nav-pills > li.open > .dropdown-menu .open .dropdown-menu {
max-height: 500px;
display: block;
visibility: visible;
-webkit-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-moz-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-o-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-webkit-transition-delay: 0s;
-moz-transition-delay: 0s;
-o-transition-delay: 0s;
transition-delay: 0s;
}
演示:http://jsfiddle.net/hhb9u7db/1/
资源:
- Transitions on the display: property
- http://davidwalsh.name/css-slide
对于 Bootstrap 默认导航栏,您可以使用以下 Less 代码:
.dropdown-menu, .open > .dropdown-menu,
{
display:block;
max-height: 0;
overflow-y:hidden;
visibility:hidden;
transition:max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu,
{
max-height: 500px;
display:block;
visibility:visible;
transition:max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition-delay:0s;
}
用 autoprefix plugin 编译成下面的 CSS 代码 (lessc --autoprefix="Android 2.3,Android >= 4,Chrome >= 20,Firefox >= 24,Explorer >= 8,iOS >= 6,Opera >= 12,Safari >= 6"
):
.dropdown-menu,
.open > .dropdown-menu {
display: block;
max-height: 0;
overflow-y:hidden;
visibility: hidden;
-webkit-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-o-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu {
max-height: 500px;
display: block;
visibility: visible;
-webkit-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-o-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-webkit-transition-delay: 0s;
-o-transition-delay: 0s;
transition-delay: 0s;
}
我在我制作的 Bootstrap 项目中有一个多级下拉菜单。我需要它,这样下拉菜单才会滑动。我该如何实现?
我已经完成了以下代码,但我需要添加到其中。以下是代码的作用:
- 如果您单击其下拉开关,它会打开和关闭 特定 下拉菜单。
- 如果您在下拉菜单外部单击,但在其父级内部单击,则只有子下拉菜单会关闭;如果您在父项外部单击,父项将关闭,依此类推。
- 如果您单击子下拉列表的下拉开关,它只会影响该下拉列表及其子项,不会其父项。
我已阅读此答案以尝试将其与我当前的解决方案一起使用,但我不知道如何使其正常工作:
我相信它有更多的规格,但你明白了。这也是我制作的一个 jsfiddle:http://jsfiddle.net/hhb9u7db/
例如,我将 Collections link 设为下拉菜单,将 T 恤 设为另一个下拉菜单。我希望这一切都像我现在的工作方式一样工作,只是它会滑动。
$(function() {
$('.dropdown').on({
"click": function(event) {
if ($(event.target).closest('.dropdown-toggle').length && $(this).parents('.dropdown').length === ($(event.target).parents('.dropdown').length - 1)) {
$(this).data('closable', true);
} else {
$(this).data('closable', false);
}
},
"hide.bs.dropdown": function(event) {
hide = $(this).data('closable');
$(this).data('closable', true);
return hide;
}
});
});
你的 fiddle 对我来说不是很清楚。您的导航栏没有 .navbar
class 并且您的导航菜单没有 .navbar-nav
.
您可以尝试添加如下所示的 CSS 代码:
.dropdown-menu,
.open > .dropdown-menu,
.dropdown-menu,
.open > .dropdown-menu .dropdown-menu {
display: block;
max-height: 0;
overflow-y:hidden;
visibility: hidden;
-webkit-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-moz-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-o-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu,
.nav-pills > li.open > .dropdown-menu,
.nav-pills > li.open > .dropdown-menu .open .dropdown-menu {
max-height: 500px;
display: block;
visibility: visible;
-webkit-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-moz-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-o-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-webkit-transition-delay: 0s;
-moz-transition-delay: 0s;
-o-transition-delay: 0s;
transition-delay: 0s;
}
演示:http://jsfiddle.net/hhb9u7db/1/
资源:
- Transitions on the display: property
- http://davidwalsh.name/css-slide
对于 Bootstrap 默认导航栏,您可以使用以下 Less 代码:
.dropdown-menu, .open > .dropdown-menu,
{
display:block;
max-height: 0;
overflow-y:hidden;
visibility:hidden;
transition:max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu,
{
max-height: 500px;
display:block;
visibility:visible;
transition:max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition-delay:0s;
}
用 autoprefix plugin 编译成下面的 CSS 代码 (lessc --autoprefix="Android 2.3,Android >= 4,Chrome >= 20,Firefox >= 24,Explorer >= 8,iOS >= 6,Opera >= 12,Safari >= 6"
):
.dropdown-menu,
.open > .dropdown-menu {
display: block;
max-height: 0;
overflow-y:hidden;
visibility: hidden;
-webkit-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
-o-transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
transition: max-height 2s ease-in-out, visibility 1.8s ease-in;
max-width: 100%;
}
.navbar-nav > li.open > .dropdown-menu {
max-height: 500px;
display: block;
visibility: visible;
-webkit-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-o-transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
transition: max-height 2s ease-in-out, visibility 0s linear 0.5s;
-webkit-transition-delay: 0s;
-o-transition-delay: 0s;
transition-delay: 0s;
}