I have decided to create a fade in animation effect using vanilla javascript.
This is the code for my fade in effect:
document.querySelector('.open-1_1').onclick = function() {
document.getElementById('about-frame').style.display = 'block';
for (opacity = 0; opacity < 1.1; opacity = opacity + 0.1)
{
setTimeout(function(){document.getElementById('about').style.opacity = opacity;},100)
}
};
What I am trying to do is incrementally increasing the opacity of the #about div from 0 to 1 by running through a for loop which is supposed to wait 100 miliseconds for every iteration of the loop
However the #about div goes from dark to opacity 1 after a set time without seeing the fade in effect.
What is wrong with my logic?
closure effect. And you actually should set a new timeout each time the previous one is processed; otherwise they all be triggered immediately after each other.