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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:32:16+00:00 2026-05-21T10:32:16+00:00

I the following code I have a UL with x3 LI’s. I want the

  • 0

I the following code I have a UL with x3 LI’s. I want the LI’s to fadeIn in a sequence but am loosing scope somewhere I think. The problem is that only the last item in the sequence is run. I initially thought this was to do with a loop, so I removed all of them. Any help would be great.

Thanks is Advance.

function Sequence() {
    var sequence = [];
    var pos = 0;

    Sequence.prototype.add = function(obj) {
        sequence.push(obj);
    };

    Sequence.prototype.start = function() {
        sequence[pos].run();
    };

    Sequence.prototype.next = function() {
        pos++;
        sequence[pos].run();
    }; 
};

function fadeIn(params) {
    this.id = params.id;
    this.onComplete = params.onComplete;

    var self = this;
    var timer;
    var i = params.opacity;

    fadeIn.prototype.run = function(){
        timer = setInterval(function() {
            params.element.style.opacity = i / 10;
            i++;

            if (i / 10 == 1) {
                clearInterval(timer);
                self.onComplete();
            }
        }, params.fps);
    }
};

var sequence = new Sequence();
var fader = document.getElementById('fader1');
var items = fader.getElementsByTagName("li");

sequence.add(new fadeIn({
    "id": "instance_0",
    "element": items[0],
    "opacity": 0,
    "fps": 80,
    "onComplete": function() {
        sequence.next();
    }
}));

sequence.add(new fadeIn({
    "id": "instance_1",
    "element": items[1],
    "opacity": 0,
    "fps": 80,
    "onComplete": function() {
        sequence.next();
    }
}));

sequence.start();
  • 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-05-21T10:32:17+00:00Added an answer on May 21, 2026 at 10:32 am

    Yes, this is a scope issue. The problem is in the line:

    fadeIn.prototype.run = function(){
    

    When you define a method on the prototype, you’re defining the method on all instances of the fadeIn class. So each time you call the constructor, you’re redefining the method with the new params in the closure.

    The solution is to define the method on this (or, as you’ve renamed it, self), which is the new instance, rather than the class:

    self.run = function(){
    

    Working example here: http://jsfiddle.net/nrabinowitz/wrQMa/3/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that works on Linux but doesn't work on Windows(VS2008)
The following page code have a problem that when i minimize the webpage the
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query
I have following code snippet that i use to compile class at the run
In the following code I have a view object that is an instance of
I have a very strange problem and the following code wont compile: #ifndef MYWINDOW_HPP_INCLUDED
I have code that I expect to return the element name, but nothing is
If I have the following code (EDIT: Sorry if I wasn't clear, I want
The following code will have PHP unhappy that customMethod() is private. Why is this
I have the following code ( I formated it to more lines, but in

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.