I am using the foreach binding along with the beforeRemove callback in order to animate the removal of my list items. It is working fine when I remove an item above the item I just previously removed, but when I attempt to remove an item below the item previously removed, the transition doesn't work correctly.
Here is a jsfiddle illustrating my issue: http://jsfiddle.net/tylerweeres/2szjxzs0/2/
HTML
<h3>Animations</h3>
<div data-bind="foreach: { data: people, beforeRemove: animateOut }">
<div style="padding: 5px;" class="person">
<span data-bind="text: name" style="display: inline-block; width: 200px;"></span>
<button style="padding: 5px 15px;" data-bind="click: $parent.removePerson">Remove</button>
</div>
</div>
CSS
.person {
font-family: georgia;
padding: 5px;
transition: all 600ms ease-in-out;
transform-origin: 75px;
}
.person.remove {
transform: translateX(2000px) rotateZ(540deg);
}
JS
function vm () {
"use strict";
var me = this;
me.people = ko.observableArray([
{ "name": "Irma Olsen" },
{ "name": "Winifred Cabrera" },
// ...
{ "name": "Lucius Howard" },
{ "name": "Hedda Santana" }
]);
me.removePerson = function (person) {
me.people.remove(person);
};
me.animateOut = function animateOut(node, i, person) {
// Make sure it's not a text node
if (node.nodeType == Node.ELEMENT_NODE) {
node.classList.add("remove");
}
}
}
ko.applyBindings(new vm());