jQuery animate()显示动画进度的百分比

时间:2012-01-23 11:26:42

标签: jquery-animate progress

使用以下代码段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想将动画#log的%进度从0%显示到100%,回调时100%很容易...

有可能吗?

此致

2 个答案:

答案 0 :(得分:3)

jQuery动画进度回调是在1.8中引入的:

$('#a').animate({
    opacity: 1,
    width: 400,
    percent: 100
}, {
    progress: function(animation, progress, msRemaining) {
        $('#log').html(100 * progress + "%");
    }
});

答案 1 :(得分:0)

我相信你可以通过使用步骤功能

来做到这一点
 $('myelementid').animate({
   opacity: 1,
   height: 100,
   percent: 100
 },
 {
   step: function(now, fx) {
      //not sure if this is 100% percent accurate 
      //but at least you have a value at every step of the animation
      console.log( this.percent );          
   },
   complete: function(){
       //do not forget to reset percent at the end of the animaton
       //so on the next animation it can be calculated from starting value of 0 again
       this.percent = 0;
   }
 });

希望这有帮助。