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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:30:33+00:00 2026-06-11T12:30:33+00:00

Suppose you have an animation running with a certain time like this: $(‘span’).animate({opacity :

  • 0

Suppose you have an animation running with a certain time like this:

$('span').animate({opacity : 1}, 10000);

The animation is quite long so the user tries clicking the button again. The animation will be a certain amount of time through the animation already, which is probably going to be different every time.

On the second click is it possible to update the animation process keeping the opacity of the object when the user clicks, just changing the time it will take to finish?

Basically I want to update the animation process mid way through the animation.

  • 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-11T12:30:35+00:00Added an answer on June 11, 2026 at 12:30 pm

    You can use the step option of animate to keep track of how far along the animation is. Then with that information, you can calculate the time remaining in the animation. Then stop the current animation and start a new one with half the duration.

    http://jsfiddle.net/MdD45/

    EDIT

    It looks like the 2nd parameter passed to step contains a property named pos which tells you what percentage along in the animation you are. That can simplify things further.

    http://jsfiddle.net/MdD45/1/

    var startVal = 0;
    var endVal = 1;
    var duration = 10000;
    
    var howfar = 0;
    
    $('span').css("opacity",startVal)
        .animate({
            opacity : endVal
        }, {
            duration: duration,
            step: function(now, fx){
                howfar = fx.pos;  // between 0 and 1, tells how far along %
            }        
        });
    
    $("button").click(function(){
        // calculate the new duration as half of the remaining duration
        var timeRemaining = duration - (howfar * duration);
        duration = timeRemaining / 2;
    
        $('span').stop().animate({
            opacity : endVal
        }, {
            duration: duration,
            step: function(now, fx){
                howfar = fx.pos;  // between 0 and 1, tells how far along %
            }        
        });
    });
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this animation that start at some point : myElement.animate({ top: -currentTempImageX,
Suppose I have some div, and I use .animate({opacity:0},400, function(){}); for its children. Is
Suppose you have to create a simple 2D animation, like the drawing of a
If I have a button, and I animate it with a simple animation like
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a VBO which remains unchanged 95% of the time. But, the
I have this property called mySegmented, declared like this .h @property (retain) UISegmentedControl *mySegmented;
Suppose I have one button, and I want it to fetch data (like an
im using jquery animation for the first time.i have read that animation can be
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,

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.