I\'m trying to make fadeOut effect for a div
with pure JavaScript.
This is what I\'m currently using:
//Imagin
Just this morning I found this piece of code at http://vanilla-js.com, it's very simple, compact and fast:
var s = document.getElementById('thing').style;
s.opacity = 1;
(function fade(){(s.opacity-=.1)<0?s.display="none":setTimeout(fade,40)})();
You can change the speed of the fade changing the second parameter in the setTimeOut
function.
var s = document.getElementById('thing').style;
s.opacity = 1;
(function fade(){(s.opacity-=.1)<0?s.display="none":setTimeout(fade,40)})();
#thing {
background: red;
line-height: 40px;
}
I will fade...