Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created December 23, 2011 17:53
Show Gist options
  • Save adamloving/1514920 to your computer and use it in GitHub Desktop.
Save adamloving/1514920 to your computer and use it in GitHub Desktop.
Knockout binding handler using jQuery fadeIn and fadeOut
ko.bindingHandlers.fade =
init: (element, valueAccessor) ->
element = jQuery(element)
value = valueAccessor()
value = ko.utils.unwrapObservable()
element.toggle(value)
update: (element, valueAccessor) ->
element = jQuery(element)
value = valueAccessor()
value = ko.utils.unwrapObservable(value)
element.fadeIn() if value
element.fadeOut() unless value
@adamloving
Copy link
Author

@collinwat and @harleyholt get credit for this, not me. I just think it is cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment