Skip to content

Instantly share code, notes, and snippets.

@didasy
Created July 20, 2015 10:52
Show Gist options
  • Save didasy/41983b9d32d389151685 to your computer and use it in GitHub Desktop.
Save didasy/41983b9d32d389151685 to your computer and use it in GitHub Desktop.
KnockoutJS Transition Binding
var prevElem = null;
// find out how to put prevElem as property and access it from update function
ko.bindingHandlers.fadeVisible = {
init: function(element, valueAccessor) {
var value = ko.unwrap(valueAccessor());
$(element).toggle(value);
},
update: function(element, valueAccessor) {
var value = ko.unwrap(valueAccessor());
if (value) {
if (prevElem == null) {
$(elem).show();
} else {
$(prevElem).fadeOut(500, function() {
$(element).fadeIn(500, function() {
// ko.postbox.publish('transition-animation-finished', $(element).attr('id'));
});
});
}
prevElem = element;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment