【发布时间】:2021-01-30 02:43:38
【问题描述】:
我有一个带有动画按钮的下拉菜单,现在我已经做到了,以便在单击内容包装容器 div 时可以关闭下拉菜单,但问题是它不考虑动画按钮返回平仓,下面是我的 HTML 和 J 的代码
function myFunction(x) {
/* This controls the animating function */
x.classList.toggle("change");
/* This controls the menu close and open */
var x = document.getElementById('Menu-cont');
if (x.style.height === "230px") {
x.style.height = "0px";
} else {
x.style.height = "230px";
}
}
/* This is a way to close menu click a container wrapper div */
document.querySelector('.content-wrapper').addEventListener('click', function(){ closeNav(); })
function closeNav() {
var x = document.getElementById('Menu-cont').style.height = "0px";
}
我希望动画按钮在单击包装 div 后动画回关闭
这是动画 html 和 css
<div class="menu-icon" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px);
transform: rotate(-45deg) translate(-9px, 6px);
}
.change .bar2 {opacity: 0;}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px);
transform: rotate(45deg) translate(-8px, -8px);
}
【问题讨论】:
标签: javascript html css animation drop-down-menu