【发布时间】:2021-07-09 03:26:51
【问题描述】:
单击按钮时会出现一个下拉菜单。问题是,下拉菜单在 PC 上一直显示动画而没有问题,但在移动浏览器上只播放一次动画(仅限第一次点击)。
function myFunction() {
var x = document.getElementById("dropdown");
if (x.className.indexOf("w3-show") == -1) {
x.classList.add("w3-show");
} else {
x.classList.remove("w3-show");
}
}
#dropdown { display:none;
border-radius: .25em;
box-shadow: 0.1em 0.1em 0.5em rgba(0,0,0,1);
background-color: rgba(0,0,0,0.3);
padding: 5px;
font-size: 22px;
color: white;
position: relative;
/* width:fit-content; */
width: 250px;
right: 0;
left: -25px;
margin: auto;}
.w3-show {
position: relative;
display: block!important;
}
.w3-animate-zoom {
animation:animatezoom 0.6s;
-webkit-animation: animatezoom 0.6s;
}
@keyframes animatezoom{from{transform:scale(0)} to{transform:scale(1)}}
<button onclick="myFunction()" class="ikincibaslik" id="buttonme">Open dropdown menu</button>
<div id="dropdown" class="show-on-scroll w3-animate-zoom" >
<a href="/imalat/indexfirst.php" class="w3-bar-item">First item</a>
<a href="/hizmet/indexsecond.php" class="w3-bar-item">Second item</a>
</div>
有什么想法吗?
【问题讨论】:
-
我在按钮点击时看不到任何动画。
x.className.indexOf("w3-show")应该是x.classList.contains('w3-show')并且它抛出 InvalidCharacterError 因为在尝试添加/删除w3-show类时有额外的空格。 -
@Spectric 现在我编辑了我的帖子以获得有效的“运行代码 sn-p”。但问题是它只在移动浏览器上播放一次。这是版本 -o-transform -moz-transform 等的问题吗?我也试过了,但可能错过了一些我不知道的东西