I thought I share what I did when I faced the need for this and wanted a clean solution that didn't mixup too much with my views or viewmodels. I came across a css framework called Just Add Water CSS.
Animations don't work on older browsers but I guess fancy UI's don't anyway. But the premise of the framework is that many useful css3 animation class are defined and you just add them as you need them.
You can animate templates like this very easily:
<button data-bind="click: toggleTemplate">Toggle template</button>
<ul id="container" data-bind="template: { name: templateToUse, foreach: items }">
</ul>
<script type="text/html" id="myTemplate1">
<li data-bind="text: $data" class="animated fadeInLeft"></li>
</script>
<script type="text/html" id="myTemplate2">
<li class="animated fadeInLeft" >Value is: <span data-bind="text: $data"></span></li>
</script>
And Vm to simulate template changes:
function vm(){
var self = this;
self.items = ko.observableArray([1,2,3,4,5,6]);
self.templateSwitch = ko.observable(false);
self.toggleTemplate = function(){
self.templateSwitch(!self.templateSwitch());
}
self.templateToUse = function(){
return self.templateSwitch() ? "myTemplate2" : "myTemplate1";
}
}
ko.applyBindings(new vm());
Here is also a fiddle