2
用下面的代碼片段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想在動畫的#log中顯示%進度從0%到100%,100%很容易回調...jQuery animate()顯示動畫進度的百分比
有沒有可能這樣做?
問候
用下面的代碼片段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想在動畫的#log中顯示%進度從0%到100%,100%很容易回調...jQuery animate()顯示動畫進度的百分比
有沒有可能這樣做?
問候
jQuery的動畫進度的回調是在1.8介紹:
$('#a').animate({
opacity: 1,
width: 400,
percent: 100
}, {
progress: function(animation, progress, msRemaining) {
$('#log').html(100 * progress + "%");
}
});
我相信你可以做到這一點通過階躍函數
$('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;
}
});
希望這有助於。