您好我正在尝试在devdojo.com(https://devdojo.com/ebook/laravelsurvivalguide)上复制漂亮的CSS转换下拉菜单,但无法复制它。它是主菜单中3个点的开始。也许我错过了什么?谢谢!
我的CSS:
.dropdown-menu-animated {
border: 0 none;
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
display: block;
margin-top: 0;
opacity: 0;
transform: scale3d(0.95, 0.95, 1) translate3d(0px, -15px, 0px);
transform-origin: 100% 0 0;
transition-delay: 0s, 0s, 0.5s;
transition-duration: 0.5s, 0.5s, 0s;
transition-property: opacity, transform, visibility;
transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
visibility: hidden;
}
.dropdown-menu {
background-clip: padding-box;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.176);
display: none;
float: left;
font-size: 14px;
left: 0;
list-style: outside none none;
margin: 2px 0 0;
min-width: 160px;
padding: 5px 0;
position: absolute;
top: 100%;
z-index: 1000;
}
.open > .dropdown-menu-animated {
visibility: visible;
opacity: 1;
transition: opacity .5s, -webkit-transform .5s;
transition: opacity .5s, transform .5s;
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
-webkit-transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
}
我的HTML:
<div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse right">
<ul class="nav navbar-nav navbar-left">
<li class="dropdown">
<a class=" dropdown-toggle" href="#_" data-toggle="dropdown">
HOVER ME
</a>
<ul class="dropdown-menu dropdown-menu-animated" role="menu">
<li>
<a href="/points">Sushi Points</a>
</li>
<li><a href="/points">Two</a></li>
</ul>
</li>
</ul>
</div>
谢谢@chiller。
更新并编辑了答案:
JS
$('.dropdown-toggle').hover(function() {
$(this).parent().addClass("open");
});
$('.dropdown').mouseleave(function() {
$(this).removeClass("open");
});
CSS
.dropdown-menu li a {
color: white;
}
.dropdown-menu-animated {
border: 0 none;
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
display: block;
margin-top: 0;
opacity: 0;
transform: scale3d(0.95, 0.95, 1) translate3d(0px, -15px, 0px);
transform-origin: 100% 0 0;
transition-delay: 0s, 0s, 0.5s;
transition-duration: 0.5s, 0.5s, 0s;
transition-property: opacity, transform, visibility;
transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
visibility: hidden;
}
.dropdown-menu {
background-clip: padding-box;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.176);
/*display: none;*/
float: left;
font-size: 14px;
left: 0;
list-style: outside none none;
margin: 2px 0 0;
min-width: 160px;
padding: 5px 0;
position: absolute;
top: 100%;
z-index: 1000;
}
.open > .dropdown-menu-animated {
visibility: visible;
opacity: 1;
transition: opacity .5s, -webkit-transform .5s;
transition: opacity .5s, transform .5s;
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
-webkit-transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
}
HTML
<div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse right">
<ul class="nav navbar-nav navbar-left">
<li class="dropdown">
<a class="dropdown-toggle" href="#_" data-toggle="dropdown">
HOVER ME
</a>
<ul class="dropdown-menu dropdown-menu-animated" role="menu" style="color:white;background:black;">
<li><a href="#">Bulanching</a></li>
<li><a href="#">Kuya Matmat</a></li>
<li><a href="#">Baby</a></li>
<li><a href="#">Wedding</a></li>
<li><a href="#">Excited</a></li>
</ul>
</li>
</ul>
</div>
答案 0 :(得分:1)
这实际上是用JavaScript完成的,你所要做的就是在你的脚本中添加这个jquery代码
$('.dropdown-toggle').hover(function() {
$(this).parent().addClass("open");
});
$('.dropdown').mouseleave(function() {
$(this).removeClass("open");
});
你必须删除display:none;从类.dropdown-menu开始动画制作
只有添加以下代码,您才可以使用CSS:
.dropdown:hover>.dropdown-menu-animated{
visibility: visible;
opacity: 1;
transition: opacity .5s, -webkit-transform .5s;
transition: opacity .5s, transform .5s;
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
-webkit-transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
transform: scale3d(1, 1, 1) translate3d(0, 0, 0);
}
答案 1 :(得分:0)
以下代码段解决了:hover
外观的样式问题。
在.dropdown .dropdown-menu-animated
规则中添加您的过渡效果,然后在那里;)
.dropdown {
float: left;
cursor: pointer;
}
.dropdown .dropdown-menu-animated {
border: 0 none;
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
margin-top: 20px;
transform: scale3d(0.95, 0.95, 1) translate3d(0px, -15px, 0px);
transform-origin: 100% 0 0;
transition-delay: 0s, 0s, 0.5s;
transition-duration: 0.5s, 0.5s, 0s;
transition-property: opacity, transform, visibility;
transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
visibility: hidden;
}
.dropdown:hover .dropdown-menu-animated {
visibility: visible;
}
<div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse right">
<ul class="nav navbar-nav navbar-left">
<li class="dropdown">
HOVER ME
<ul class="dropdown-menu-animated" role="menu">
<li>
<a href="/points">Sushi Points</a>
</li>
<li><a href="/points">Two</a></li>
</ul>
</li>
</ul>
</div>