Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:48:45+00:00 2026-06-11T14:48:45+00:00

In trying to spice up a knockout.js UI with effects, I’ve found that I

  • 0

In trying to spice up a knockout.js UI with effects, I’ve found that I often have several sections that alternate based on a conditional. An example of this could be a details pane in a list view that displays instructions when no element is selected. This works great declarativly using the visible binding – but it falls short when you attempt to add animations to the mix, since there’s no chaining of the show / hide animations.

I’ve simplified the animation knockout.js example here to demonstrate:

http://jsfiddle.net/yq5rS/

While I could probably hack something, I’m looking for a more idiomatic knockout.js way of doing this kind of chaining.

I’ve considered a few solutions:

  • Having a container element with a custom binding that captures the conditional and which element to show in the on and off states.
  • Having the “animation visible” binding dependent on both the conditional and a function that checks if the other element is hidden.

Edit: To be clear, I want the fade out of one element to happen before the fade in of the other. Thanks Josh.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:48:46+00:00Added an answer on June 11, 2026 at 2:48 pm

    This approach creates a computed observable that looks to the boolean observable to determine which text to display.

    Here’s a working jsfiddle. http://jsfiddle.net/yq5rS/10/

    And here’s a quick idea of the code

    Html

    <div class='liveExample'> 
        <p> 
            <label>
                <input type='checkbox' data-bind='checked: display' />
                Active?
            </label>
        </p>
    
        <p data-bind='fadeVisible: IsActive()'></p>    
    </div>​
    

    Scripts

    var Model = function() {
        var self = this;
        self.display= ko.observable(false);
        self.IsActive = ko.computed(function() {
            if (self.display()) return "Active."
            return "Not active."
        }); 
    };
    
    
    ko.bindingHandlers.fadeVisible = {
        init: function(element, valueAccessor) {
            var value = valueAccessor();
            $(element).hide().html(ko.utils.unwrapObservable(value)).fadeIn();
        },
        update: function(element, valueAccessor) {
            var value = valueAccessor();
            $(element).hide().html(ko.utils.unwrapObservable(value)).fadeIn();
        }
    };
    
    ko.applyBindings(new Model ());​
    

    EDIT

    My initial response did not fade out, wait, and then fade back in. Here is an updated fadeVisible binding handler

    ko.bindingHandlers.fadeVisible = {
        update: function(element, valueAccessor) {
            var value = valueAccessor();
            $(element).fadeOut('slow', function () {
                $(element).html(ko.utils.unwrapObservable(value)).fadeIn();
            });
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save space in my executable and I noticed that several
I am trying to space out DIVs. I have five DIVs that are 30px
trying to use regex to replace any white space with &nbsp;, inside of example
I am trying to implement slice functionality for a class I am making that
I'm trying to spice up my website by using custom fonts for headings. For
I'm trying add a space before a particular string ( Token for example) by
I'm trying to splice an image and then have a transition to next one
I am working on a piece of code that I am wanting to spice
Hello I am trying to bind my work space and I have been doing
I'm trying to remove white space between tags so that childNodes only contain those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.