wants to change the opacity, of the element by constantly executing the timer, but only the opacity of the element obtained by the function each time is 0, which is not accumulated. The code is as follows:
function appear () {
var opity = document.getElementById("fade-obj").style.opacity;
console.log(document.getElementById("fade-obj").style.opacity);
if(opity != 1) {
document.getElementById("fade-btn").disabled = "true";
opity += 0.2;
document.getElementById("fade-obj").style.opacity = opity;
setTimeout(appear,500);
}else{
document.getElementById("fade-btn").innerHTML = "";
document.getElementById("fade-btn").removeAttribute("disabled");
}
}
document.getElementById("fade-btn").addEventListener("click", function() {
if (document.getElementById("fade-btn").innerHTML == "") {
setTimeout(appear,500);
}
}, false)
the results are as follows:
I don"t know why the value of document.getElementById ("fade-obj") .style.opacity remains the same