Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery.animate()-在.each()中增加数字_Jquery_Load_Jquery Animate_Each - Fatal编程技术网

jQuery.animate()-在.each()中增加数字

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:

如果有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: 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){