简体   繁体   English

在$ .each中使用append显示整个数组

[英]Using append in $.each shows whole array

Okay, so I have an array of characters and i'm wanting them to display one at a time. 好的,所以我有一个字符数组,我希望它们一次显示一个。 This is the code i'm trying to use: 这是我正在尝试使用的代码:

$.each(characterarray, function( index, value ){
   $("div").fadeOut(300).delay( 10 ).append( value ).fadeIn(300);
});

So instead of fading out, waiting, append one of the array, and fade in. 因此,不是淡出,等待,附加其中一个数组,然后淡入。

It would: fade out, wait, append all of the array, and fade in. 它会:淡出,等待,附加所有阵列,然后淡入。

When I used 我用的时候

alert( value );

and it would apply an alert for each letter, but when I tried the to append it would show all of the array at once. 并且它会为每个字母应用一个警报,但是当我尝试追加它时会立即显示所有数组。

The loop finishes immediately, you'll have to increment the delay 循环立即结束,你必须增加延迟

$.each(characterarray, function( index, value ){
     $("div").delay(index*1000).fadeOut(300, function() {
        $(this).append( value ).delay(10).fadeIn(300);
     });
});

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM