jQuery.animate()-在.each()中增加数字
如果有3张图片。动画将同时运行3次。因为我想一次做30和100的事情。有什么解决办法吗jQuery.animate()-在.each()中增加数字,jquery,load,jquery-animate,each,Jquery,Load,Jquery Animate,Each,如果有3张图片。动画将同时运行3次。因为我想一次做30和100的事情。有什么解决办法吗 img.each(function(e){ var image = $(this); image.load(function(){ // load 3 images currentValue += eachOfImg; // eachOfImg = 100/3 jQuery({someValue: startValue}).animate({someValue:
img.each(function(e){
var image = $(this);
image.load(function(){ // load 3 images
currentValue += eachOfImg; // eachOfImg = 100/3
jQuery({someValue: startValue}).animate({someValue: currentValue}, {
duration: 3000,
step: function() {
console.log('currentValue:',this.someValue);
if(someValue == 30) // do something
if(someValue == 100) // do something
$('.text').text(Math.ceil(this.someValue) + "%");
}
});
});
});
Chrome控制台输出为:
(3) currentValue: 0
(8) currentValue: 1
currentValue: 2
(2) currentValue: 1
currentValue: 2
currentValue: 1
(2) currentValue: 2
currentValue: 1
(2) currentValue: 2
currentValue: 1
currentValue: 2
currentValue: 3
currentValue: 1
currentValue: 2
我预计它将:
currentValue: 0
currentValue: 1
currentValue: 2
currentValue: 3
currentValue: 4
currentValue: 5
currentValue: 6
currentValue: 7
currentValue: 8
currentValue: 9
...
谢谢这段代码没有多大意义,我认为你需要更好地解释你想做什么。动画在过程中的位置的值是step函数中的一个参数,通常命名为
now
,例如:step:function(now,fx){if(now>30)}
使选择器特定于单个图像,或者在if
条件中包含一个标志,类似于if(value==30&!functionexecuted){