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 8771165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:43:03+00:00 2026-06-13T17:43:03+00:00

I want to implement this simple animation in knockout: function scroll(back) { var scrollContainer

  • 0

I want to implement this simple animation in knockout:

function scroll(back) {
    var scrollContainer = $('.scrollingContent');
    var newContent = $("<div class='content'></div>");
    var oldContent = scrollContainer.children().first();
    newContent.css("width", "50%");
    var contentSize = oldContent.width();
    var newContentColor = oldContent.css("background-color") == "rgb(255, 0, 0)" ? 
                                                                "green" : "red";
    newContent.css("backgroundColor", newContentColor);
    if (back) {
        newContent.css("margin-left", -contentSize);
        scrollContainer.prepend(newContent);
        newContent.animate({ "margin-left": 0 }, 600, 
        function () { oldContent.remove(); });
    } else {
        scrollContainer.append(newContent);
        oldContent.animate({ "margin-left": -contentSize }, 600, 
        function () { oldContent.remove(); });
    }
}

Example can be looked at here: http://jsfiddle.net/VMx3j/106/

I’ve read a lot about custom bindings, but I still can’t understand how to do it right.

I had just two ideas. First was to create an foreach array and to bind on afterRender, afterAdd, or beforeRemove. But will it be correct? I think the code in this case won’t be enough understandable and it will be very hard to change anything. Also another idea was to create a custom binding. But as far as I understood this approach works only with one element, and I need access to at least two of them.

Also notice that content element is template (that is constantly changed by this animation).

Please help if you have any ideas about it.

  • 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-13T17:43:04+00:00Added an answer on June 13, 2026 at 5:43 pm

    Here is the correct answer:

    this.afterElementAdd = function(element) {
        if (element.nodeType === 1) {
            var el = $(element);
            if (el.next().length != 0 && el.prev().length == 0) {
                el.animate({ "margin-left": "0" }, 300, function () {
                    self.contents.pop();
                });
            }
            else if (el.prev().length != 0 && el.next().length == 0) {
                el.prev().animate({ "margin-left": -el.width() }, 300, function () {
                    self.contents.shift();
                });
            }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
This is the class I want to implement the onClickListener in: private void updateUserListView(DatabaseHandler
I want to implement a simple animation based on UIView's center property. I have
I want to implement this simple form but its in old rails. Can somebody
I want to implement this view But I have one question: The text which
I want to implement this JSF page with pagination and sorting. Unfortunately Netbeans shows
First, I know about Clog , and I do not want to implement this
i starter in jqgrid, i want implement inline edit in jqgrid i have this
I have this algorithm that I want to implement on VB6. Sub Main() dim
I want to implement tomb-stoning in my WP7 app and this app is not

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.