我正在制作一个CSS和Javascript的动画菜单,并与它的问题。这个想法是有一个菜单与不透明度:0(使用CSS)在第一次然后通过点击汉堡菜单不透明度成为1和菜单滑到右边一点(使用Javascript).菜单飞在罚款,但在点击汉堡X按钮,它不会再次飞出和X不会改变汉堡图标.
这是一个CSS动画(过渡会更容易吗?))
下面是代码:
let d = document.getElementsByClassName("show")[0];
let f = document.getElementsByClassName("menu")[0];
let o = document.getElementsByClassName("burger")[0];
let p = document.getElementsByClassName("burgers")[0];
d.toggleStatus = "off";
f.onclick = function() {
switch (d.toggleStatus) {
case "off":
d.toggleStatus = "on";
d.setAttribute('style', 'animation-play-state:running');
break;
case "on":
d.toggleStatus = "off";
d.setAttribute('style', 'display:none');
break;
}
o.classList.toggle('rotate');
p.classList.toggle('rotate2');
}
.show {
opacity: 0;
animation: menu .3s ease-out;
animation-play-state: paused;
animation-fill-mode: forwards
}
@keyframes menu {
0% {
margin-right: 190px;
opacity: 0
}
100% {
margin-right: 89px;
opacity: 1
}
}
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
<div class="menu">
<div class="burger"><img src="https://picsum.photos/50" /></div>
<div class="burgers"><img src="https://picsum.photos/50" /></div>
</div>
<div class="show pt-20 min-w-screen text-center min-h-screen">
<a href="#"><span>Home</span></a>
<a href="#"><span>About</span></a>
<a href="#"><span>Work</span></a>
<a href="#"><span>Contact</span></a>
</div>
请在全屏上查看页面。
1条答案
按热度按时间bkhjykvo1#
您可以使用
transition
沿着类切换。