Is there a way to make the font color change to red and then back to white when a new item is added to a play by play array using knockout? I know how to achieve this effect on a single property with the provided binding, but I'm unsure of how to do it for a new object being added to the DOM.
ko.bindingHandlers.flash = {
init: function (element, valueAccessor) {},
update: function (element, valueAccessor) {
var updated = valueAccessor().updated;
if (updated()) {
$(element).addClass('flash');
setTimeout(function () {
$(element).removeClass('flash');
}, 1000);
updated(false);
}
}
};
CSS
.flash {
color: red;
-webkit-transition: color 0.4s ease;
-moz-transition: color 0.4s ease;
-o-transition: color 0.4s ease;
transition: color 0.4s ease;
}
HTML
<div class="accordion-inner period-play-by-play" data-bind="foreach: plays">
<div class="play" data-bind="css: {'home-team': $data.IsHomeTeam, 'away-team': !$data.IsHomeTeam, 'modified': $data.isNew}">
<b data-bind="text: $data.Time + ' '"></b>
<span data-bind="text: $data.Team + ' ' + $root.actionName($data.Action)"></span>
<span data-bind="text: $root.actionTypeName($data.ActionType)"></span>
<span>by <i data-bind="text: $data.Name"></i></span>
<!-- ko if: $data.Lead != '' -->
<div class="pull-right" data-bind="text: $data.Lead"></div>
<!-- /ko -->
</div>
</div>