I have a dropdown menu appearing on button click. The problem is, the dropdown menus is appearing with animation all time without problem on PC, but plays with animation only once (on first click only) on mobile browsers.
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>
Any ideas?
x.className.indexOf("w3-show")is supposed to bex.classList.contains('w3-show')and it's throwing a InvalidCharacterError because you have extra spaces when when trying to add/remove thew3-showclass.