Created
July 20, 2015 10:52
-
-
Save didasy/41983b9d32d389151685 to your computer and use it in GitHub Desktop.
KnockoutJS Transition Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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