English 中文(简体)
是否有办法获得剩余的估计时间?
原标题:Is there any way to get the remaining time of animation?

Suppose I have some div, and I use .animate({opacity:0},400, function(){}); for its children. Is it ever possible then to get the remaining time for an animation to complete? eg, 200 ms remaining, or 0 if there s no animation? Thanks.

最佳回答

To help you better understand how you can use the step function [as posted by gdoron]
I created an example using the step function to get the remaining time:

(click the get state!thton to end the animation and rec themain time!)

demo with distance
demo with opacity

远距离学习 j 质量:

var time = 4000;
var distance = 300;
var currentTime = 0;

$( #ball ).animate({
    left: distance
}, {
    duration: time,
    step: function (now, fx) {

        currentTime = Math.round((now * time) / distance);
        var data = fx.prop +     + Math.round(now) +  ; <b>  + currentTime +  ms</b>  ;

        $( body ).append( <p>  + data +  </p> );
    },
    easing:  linear 
});

$( #getTime ).click(function () {
    $( #ball ).stop();
    $( body ).prepend( <p>currentTime is:  + currentTime +   ms; REMAINING:   + (time - currentTime) +  ms</p> );
});
  • You can see how I used the fx.prop inside the animation step to get the (left) property that is currently animated.
  • You can see how: knowing the animation time and the distance (opacity, whatever...) we can easily retrieve the stopped/paused state by some simple math ((now*time)/distance) and thanks to the returned now value.
问题回答

我不知道为什么需要,但<条码>步骤<>/代码>。 帮助您获取这一价值:

<>功能>

第2版的囚犯(a)提供了一种步骤选择,即向 each升的每一步发射击退功能。 这一职能有助于使习惯的估算类型成为可能,或改变正在发生的估算。 它接受两个论点(现在和fx),这属于正在消化的多功能元素。

now: the numeric value of the property being animated at each step
fx: a reference to the jQuery.fx prototype object, which contains a number of properties such as elem for the animated element, start and end for the first and last value of the animated property, respectively, and prop for the property being animated.

rel=“nofollow noreferer”>docs

名单永远不会忘记<条码>步骤<>。 我曾经需要你做些什么,并写过我自己的话,简单地把它倒掉了剩下的时间,看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看一看(你一把这个数字 j倒就知道了)和“<>引人<>目前和目标不透明”。 然后,这种引人与总估算时间相乘,总金额从总时间中减去。 简单。

www.un.org/spanish/ecosoc Pseudo-code:

func calculate-time-left-in-a-running-fade-in-animation:
{
    var current_opacity = $elem.css( opacity );
    var target_opacity = this.getTargetOpacity();

    var total = this.getTotalAnimationTime();

    var quotient = current_opacity / target_opacity;
    return total - quotient * total;
}




相关问题
images sliding continuously with <table> and jQuery

I m trying to write a little test page that circulates images through a window (see image). I have colored boxes inside a table (gray border), with each box being a element. <table id="boxes" ...

WPF 3d rotation animations

I have a few 3d rectangles on my screen that I want to pivot around the Y axis. I want to press down with the mouse, and rotate the 3d object to a max rotation, but when the user moves their mouse, ...

Disable Windows 7 touch animation in WPF

In Windows 7 when you touch the screen there is a short animation that occurs at the touch point. In my WPF app I want to display my own touch points, without showing the one supplied by Windows. ...

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

Visual State Manager VS Animations in WPF

There is a lot of talk about the simplicity of Visual States and the transitions between them in WPF/Silverlight. I have the need to generate animations dynamically at runtime, to animate the ...

Create a ImageIcon that is the mirror of another one

I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签