Created
May 21, 2014 21:06
-
-
Save dzerrenner/561bde7a2c97ab95d699 to your computer and use it in GitHub Desktop.
Knockout.js custom binding handler to show / hide an element with jQuery's slideUp / slideDown methods
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
ko.bindingHandlers.slideToggleVisible = { | |
init: function(element, valueAccessor) { | |
var value = valueAccessor(); | |
ko.unwrap(value) ? $(element).show() : $(element).hide(); | |
}, | |
update: function(element, valueAccessor) { | |
var value = valueAccessor(); | |
ko.unwrap(value) ? $(element).slideDown() : $(element).slideUp(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
while expanded is an observable returning the current visible state of the element.