Start Test
HTML...
<table id="tbl">
<tbody>
<tr>
<td>row 1</td>
</tr>
<tr>
<td>row 2</td>
</tr>
</tbody>
</table>
CSS...
tr:nth-child(odd) td {
background-color: lightgrey;
}
tr td {
background-color: white;
}
tr td.animate {
-webkit-transition-property: background;
-webkit-transition-duration: 15s;
-moz-transition-property: background;
-moz-transition-duration: 15s;
transition-property: background;
transition-duration: 15s;
}
tr td.over {
background-color: red;
}
JavaScript
var ColourNextCell = function(fpsDiv, time, frames, tbl, x, y) {
var tbody = tbl.childNodes[0];
if (x >= tbody.childNodes[y].childNodes.length) {
x = 0;
y++;
}
if (y > tbody.childNodes.length) {
y = 0;
}
var currentTime = new Date().getTime();
if (currentTime - time > 1000) {
fpsDiv.html(String(frames));
time = Math.floor(currentTime/1000)*1000;
frames = 0;
}
var jqEl = $(tbody.childNodes[y].childNodes[x]);
var timeoutId = jqEl.data("timeoutId");
if (timeoutId) {
clearTimeout(timeoutId);
}
jqEl.addClass("over");
setTimeout(function() {
jqEl.addClass("animate")
jqEl.data("timeoutId", setTimeout(function() {
jqEl.removeClass("over");
jqEl.data("timeoutId", setTimeout(function() {
jqEl.removeClass("animate");
}, 15000));
}, 0));
}, 100); // in firefox this needs to be 100 to ensure red applies itself before animate. In chrome it is not needed
setTimeout(function() { ColourNextCell(fpsDiv, time, frames + 1, tbl, x+1, y); }, 0);
};