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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:46:45+00:00 2026-05-29T05:46:45+00:00

element is called but never used, they are just passed back to a another

  • 0

element is called but never used, they are just passed back to a another function call. This seems like a waste is there a better way to do this?

Initial Call

fadeUp( document.getElementById( 'test' ), 3000 );

Fades the opacity of an element up for 3000 ms

function fadeUp( element, max_time )
{
    var opacity = 0;
    if( fadeUp.elapsed === undefined )
    {
        fadeUp.elapsed = 0;
    }
    fadeUp.elapsed += 10;
    opacity = fadeUp.elapsed / max_time; 
    setTimeout(function(){callBack( element, max_time, fadeUp.elapsed, opacity );},fadeUp.elapsed);
}

function callBack( element, max_time, elapsed, opacity )
{
    element.style.opacity = opacity;
    if( elapsed <= max_time )
    {
        fadeUp( element, max_time );
    }
    else
    {
        fadeUp.elapsed = undefined;
    }
}

Related

How to create an opacity fade()? ( improvement over jQuery)

  • 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-29T05:46:46+00:00Added an answer on May 29, 2026 at 5:46 am

    The element argument is used in the callback function. If you eliminate it from the fadeUp() function, then it will not be available to the callback function and your code will not work. This is the proper way to pass element for use in the callback and there is not a better way to get that argument to the callback function.

    If I follow what you’re trying to do, then I think you can use this much simpler code that uses no static variables:

    function fadeUp( element, max_time ) {
        var elapsed = 0;
    
        function next() {
            elapsed += 10;
            element.style.opacity = Math.min(elapsed / max_time, 1);
            if (elapsed <= max_time) {
                setTimeout(next, 10);
            }
        }
        next();
    }
    

    You can see it work here: http://jsfiddle.net/jfriend00/FHq6B/.

    This uses a local function and local variables with no static variables.

    And, a slightly more accurate version that uses actual elapsed time to calculate the amount of fade would look like this:

    function fadeUp( element, max_time ) {
        var startTime = (new Date()).getTime();
    
        function next() {
            var elapsed = (new Date()).getTime() - startTime;
            element.style.opacity = Math.min(elapsed / max_time, 1);
            if (elapsed <= max_time) {
                setTimeout(next, 10);
            }
        }
        next();
    }
    

    This one can be seen here: http://jsfiddle.net/jfriend00/g98Tv/.

    Note the additional accuracy of using actual elapsed time is probably not noticeable with a fade animation, but can be noticeable with other types of animations which is why I included it here.

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

Sidebar

Related Questions

From inside of the fireAlert() function, how can I reference the element that called
I'm programmatically replacing a UITextField with a UITextView, but this seems to break something
Suppose I have an element called #container-main . How do I make that display:none
I have an element for my side bar navigation being called from my layouts/default.ctp
I know that to filter an element with an atttribute called attrName which has
I have a data.frame in R; it's called p . Each element in the
I need to add an Anchor with a specific ClickHandler into an Element. But
The problem behind my question in the title is this: jQuery( document ).ready( function()
I have a Windows Forms DropDown element called tsmiSendFeedback . I'm trying to bind
I have a table that looks something like this: <table> <tr id=header> <th>Title</th> <th>Title</th>

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.