Below is my code, it shows normal at the beginning, however, as long as the number of fade out go to almost 20 times, then strong flickering occur, could anyone tell where it get wrong and how to fix it? Thanks.
function change() {
let abc = document.getElementById("myDIV");
abc.className = "mystyle";
let aa = setInterval(function() {
if (abc.className === "mystyle") {
abc.className = "";
}
}, 1000);
setTimeout(function() {
clearInterval(aa)
}, 1000);
setInterval(change, 2000);
return
}
.mystyle {
background-color: coral;
padding: 16px;
opacity: 0;
transition: opacity 1s linear;
}
<div id="myDIV">
<p>I am myDIV.</p>
</div>
<p>Click the button to set a class for myDIV:</p>
<button onclick="change()">Try it</button>