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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:10:11+00:00 2026-06-01T16:10:11+00:00

The question I have is how to I get multiple instances of a function

  • 0

The question I have is how to I get multiple instances of a function to run. Here is my function below – A simple fade function. Problem I’m having is that when it is called a second time it abandons the first call. So if a user clicks on a button it will display a message which fades.

If the user clicks on another button the previous fading message just stops at the current opacity level.

?

What is the stopping mechanism? Where did the previous function go?

The function

function newEffects(element, direction, max_time ) 
{
    newEffects.arrayHold = [];
    newEffects.arrayHold[element.id] = 0;

    function next() 
    {
        newEffects.arrayHold[element.id] += 10;
        if ( direction === 'up' )
        {
            element.style.opacity = newEffects.arrayHold[element.id] / max_time;
        }
        else if ( direction === 'down' )
        {
            element.style.opacity = ( max_time - newEffects.arrayHold[element.id] ) / max_time;
        }
        if ( newEffects.arrayHold[element.id] <= max_time ) 
        {
            setTimeout( next, 10 );
        }
    }
    next();
    return true;
};

The Call

newEffects(this.element, 'down', 4000 ); 

Old Object

/**
 *    Effects - causes all elements that are fading to sync. to same opacity level as they share the same elapsed time.
 */

var Effects = function( element ) 
{
    this.element = element;
};

Effects.prototype.fade = function( direction, max_time ) 
{
    Effects.elapsed = 0;
    var persist_element = this.element;
    function next() 
    {
        Effects.elapsed += 10;
        if ( direction === 'up' )
        {
            persist_element.style.opacity = Effects.elapsed / max_time;
        }
        else if ( direction === 'down' )
        {
            persist_element.style.opacity = ( max_time - Effects.elapsed ) / max_time;
        }
        if ( Effects.elapsed <= max_time ) 
    {
            setTimeout( next, 10 );
        }
    }
    next();
    return true;
};
  • 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-01T16:10:13+00:00Added an answer on June 1, 2026 at 4:10 pm

    Try this

    function newEffects(element, direction, max_time ) 
    {
        var mt=max_time;
        var dir=direction; 
        var el=document.getElementById(element);
        var newEffects={};
        newEffects.arrayHold = [];
        newEffects.arrayHold[el.id] = 0;
    
        function next() 
        {
            newEffects.arrayHold[el.id] += 10;
            if ( dir === 'up' )
            {
                el.style.opacity = newEffects.arrayHold[el.id] / mt;
            }
            else if ( dir === 'down' )
            {
                el.style.opacity = ( mt - newEffects.arrayHold[el.id] ) / mt;
            }
            if ( newEffects.arrayHold[el.id] <= mt ) 
            {
                setTimeout( next, 10 );
            }
        } next();
    };
    

    An example is here.

    Declare every variable using var keyword inside the parent function to
    keep separate instance of each items, this is how clouser works.

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

Sidebar

Related Questions

I have a question about the JFileChooser in Swing. I'm trying to get multiple
Here is my question. I have this model one [Event] has multiple [Day] and
I am building a page that will have multiple instances of a tag such
I have a question about JSF and GET http request. How can I get
I have a question regarding how to get a div height. I'm aware of
I have a Question class: class Question { public int QuestionNumber { get; set;
I have few Question for which I am not able to get a proper
I have a question. How could I get the data from a google search
I have this question relating to Lucene. I have a form and I get
I managed to get some help from a previous question and I have the

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.