I would like to make a div appear with fade effect :
<div id="toto" style="background:red;width:200px;height:200px"></div>
The simplest way I know is with CSS properties "transition" and "opacity". In my mind, this code should works (but it doesn't) :
document.getElementById("toto").style.opacity = 0;
document.getElementById("toto").style.transition = "all 5s ease";
document.getElementById("toto").style.opacity = 1;
(See at : http://jsfiddle.net/87q44ysg/1/#share)
Anyone know why ?? I have found this hack but I can't explain why it works in this case only... :
document.getElementById("toto").style.opacity = 0;
window.setTimeout(function(){
document.getElementById("toto").style.transition = "all 5s ease";
document.getElementById("toto").style.opacity = 1;
}, 1);
(See at : http://jsfiddle.net/36009t1x/#share)
Thank you !