一个菜单按钮特效案例,简单的实现了动态效果。

代码效果预览地址:

http://code.w3ctech.com/detail/2504

<div class="bar" id="menubar">

  <div class="menu" id="menu0">

  </div>
<div class="menu" id="menu1"> </div>
<div class="menu" id="menu2"> </div>
</div>
 .bar{
width:40px;
height:40px;
border:1px solid #ccc;
border-radius:50%;
position:fixed;
top:10px;
right:25px;
z-index:;
cursor:pointer;
}
.menu{
width:20px;
height:2px;
background-color:#ccc;
position:absolute;
transform:translate3d(-50%,-50%,0);
left:50%;
transition:all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s
}
#menu0{
top:30%;
}
#menu1{
top:50%;
}
#menu2{
top:70%;
}
 window.onload = function () {
var menubar = document.getElementById("menubar");
var menu0 = document.getElementById("menu0");
var menu1 = document.getElementById("menu1");
var menu2 = document.getElementById("menu2");
var i = 0;
menubar.onclick = function () {
i++;
if (i % 2 == 1) {
menu0.style.top = 50 + "%";
menu1.style.display = "none";
menu2.style.top = 50 + "%";
menu0.style.transform = "translate3d(-50%,-50%,0) rotate(135deg)";
menu2.style.transform = "translate3d(-50%,-50%,0) rotate(405deg)";
}
else {
menu0.style.transform = "translate3d(-50%,-50%,0) rotate(0deg)";
menu2.style.transform = "translate3d(-50%,-50%,0) rotate(0deg)";
menu0.style.top = 30 + "%";
menu2.style.top = 70 + "%";
menu1.style.display = "block";
}
} }
05-08 15:41