I'd suggest using CSS animations:
@-mozilla-keyframes newRowAdded {
from {
background-color: #ffa;
}
to {
background-color: #fff;
}
}
@-ms-keyframes newRowAdded {
from {
background-color: #ffa;
}
to {
background-color: #fff;
}
}
@-o-keyframes newRowAdded {
from {
background-color: #ffa;
}
to {
background-color: #fff;
}
}
@-webkit-keyframes newRowAdded {
from {
background-color: #ffa;
}
to {
background-color: #fff;
}
}
@keyframes newRowAdded {
/* 'from' is that starting position/frame */
from {
background-color: #ffa;
}
/* 'to' is the final position/frame */
to {
background-color: #fff;
}
}
.newrow {
/* first: the animation-name,
second: the animation duration (s for seconds): */
-moz-animation: newRowAdded 2s;
-ms-animation: newRowAdded 2s;
-o-animation: newRowAdded 2s;
-webkit-animation: newRowAdded 2s;
animation: newRowAdded 2s;
}
JS Fiddle demo.
The, inevitable, down-side of using CSS animations is that older browsers, particularly, but not limited to, Internet Explorer, will be unable to implement this solution. To attend to those incompatible browsers, if you're willing, and able, to implement jQuery UI as well as jQuery itself:
$("#add").click(function (event) {
event.preventDefault();
$("#numlist tbody").prepend("<tr class='newrow'><td>somenum</td></tr>").find('.newrow:first').css('background-color', '#ffa').animate({
'background-color' : '#fff'
}, 2000);
});
JS Fiddle demo.
Note that jQuery itself cannot animate the color
or background-color
property of an element, jQuery UI, however, can. Though there's an alternate jQuery color plugin that also adds this facility, which may be more lightweight than adding the minimised (and only the relevant modules from) jQuery UI.
References: