I have a table with a number of data rows, which is zebra striped using the following CSS:
#datatable tr:nth-child(odd) {
background-color: #fff;
}
#datatable tr:nth-child(even) {
background-color: #fafafa;
}
The data in the table is continually updated via ajax calls, and I want to add a temporary highlight to particular rows where data has changed.
I want this new colour (red if the data value has decreased, green if the data value has increased), to nicely fade in, stay for a second or two, then fade back out to the original row colour again.
I have this working just now using jQuery and CSS;
$('#row_id').addClass("temphighlight");
setTimeout(clearHighlighting, 3000);
function clearHighlighting(){
$("#row_id").removeClass("temphighlight");
}
#datatable tr.temphighlight {
background-color: #c6efce;
transition: background 1.0s ease;
}
This works for the fade in, but after the delay, the CSS class is removed immediately and there is no fade out.
How can I get this highlighting to have a better effect, where it fades in and also fades out?
I have checked several similar SO questions, but the answers either don't work or don't apply - such as suggestions that you animate a fade to white, which doesn't work for me because my rows are alternatively coloured differently due to the row striping.