我想切換下拉菜單,單擊時動畫下拉,然後在另一次單擊時備份。這是動畫,但不支持。它正在消失。使用toggleClass切換使用JQuery的CSS動畫
這裏是我的codepen:
http://codepen.io/omarel/pen/YZPyOg
JQUERY
$(".openNav").click(function() {
$('.navdropdown').toggleClass("slidenavdown");
});
HTML
<a href="javascript:;" class="openNav">open</a>
<div class="navdropdown">
<div class="holdcenter">
<ul>
<li><a href="#buildingcontainer">hello</a></li>
</ul>
</div>
</div>
CSS
.openNav {
position:fixed;
top:0px;
left:0px;
z-index:1000
}
.navdropdown {
position: fixed;
top:-100%;
width:100%;
height:100vh;
background-color: #000;
z-index:5;
}
.navdropdown .holdcenter {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
overflow-y: auto;
}
.navdropdown ul > li {
display: block;
position: relative;
text-align: center;
font-size:38px;
letter-spacing: 9.5px;
margin:27px auto;
}
.navdropdown.on {
height:100vh;
}
.slidenavdown {
-webkit-animation: slidenavdown;
-moz-animation: slidenavdown;
-o-animation: slidenavdown;
animation:slidenavdown;
}
.slidenavdown {
animation-iteration-count: 1;
-webkit-animation-iteration-count: 1;
animation-fill-mode: both;
-webkit-animation-fill-mode: both;
}
.x {
-webkit-animation-direction: alternate-reverse;
animation-direction: alternate-reverse;
}
/* --- DELAYS --- */
.x {
-webkit-animation-delay: .2s;
animation-delay: .2s;
}
/* --- SPEED --- */
.slidenavdown {
-webkit-animation-duration: 0.8s;
animation-duration: 0.8s;
}
/* --- EASING --- */
.slidenavdown {
-webkit-animation-timing-function: cubic-bezier(.86,.03,.53,1.01);
animation-timing-function: cubic-bezier(.86,.03,.53,1.01);
}
/* --- TRANSITIONS --- */
.x {
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
}
/* --- KEYFRAMES --- */
@keyframes slidenavdown {
0% {
top:-100%;
}
100% {
top:0px;
}
}
如果您已經使用jQuery,那麼爲什麼不讓它做,而不是試圖內做動畫CSS?你不必維護所有的代碼。 – Slime
我想用這些CSS動畫代替。 – Omar