Reputation:
Does anyone know why my javascript doesn't work AS IT IS? Below is the code:
function load(){
function fadein(){
var op = document.getElementsByClassName("load_1")[0]
op.style.opacity = 0;
function animate(){
if ((op.style.opacity = op.style.opacity + 0.01) < 1){
alert("Hello")
requestAnimationFrame(animate);
}
}
animate()
}
fadein()
}
load()
Upvotes: 0
Views: 48
Reputation: 61
I know you said you wanted it to work exactly the way it so, so I apologise if my suggestions are going a bit overboard, but I couldn't get it to work the way you have it for the below reasons:
Find below a suggestion code. It has multiple changes but hopefully not too many as you wished for.
var op = document.getElementsByClassName("load_1")[0];
load();
function load(){
fadein();
animate();
}
function animate(){
var opac = parseFloat(op.style.opacity);
opac = opac+0.1;
op.style.opacity = opac;
if ((op.style.opacity) < 1){
alert("Hello");
requestAnimationFrame(animate);
}
}
function fadein(){
op.style.opacity = 0.1;
}
Upvotes: 1