I have this element, which is of black color initially:
<div class="dot"></div>
And then, I'm trying to make it gradually fade in to rgba(255, 255, 255, 1)
. However, using a simple for
from 1 to 255 makes it instantly go white, and what I want is something that would last at least half a second, so I tried this:
for (var i = 0; i <= 255; i++) {
colorDot(i, i, i);
}
function colorDot(r, g, b) {
setTimeout(function() {
$(".dot").css("background-color", "rgba("+r+","+g+","+b+", 1)");
}, 10);
}
which doesn't seem to work either, as the colorDot
function will return immediately, and the next iteration will execute. Any way I could make this work?