简体   繁体   English

如何仅使用jQuery一次将动画随机化一次

[英]How to randomize animation once at a time only using jquery

I'm new to jquery. 我是jquery新手。 I have a value in array as 我在数组中有一个值

var obj = [{'com':'something'},{'com':'some other thing'}];

and my animation as like this : https://codepen.io/R4ver/pen/EHlpF?page=8 和我的动画是这样的: https : //codepen.io/R4ver/pen/EHlpF?page=8

i want to append the above obj array values to the animation how to show in a sequence one by one ., i created animation but can't able to append the animation 我想将上述obj数组值附加到动画中,如何按一个序列依次显示。,我创建了动画,但无法附加动画

i tried this one but it simply alert the com values( i want to miggle with the animation as above) : 我尝试了这个,但是它只是警告com值(我想与上面的动画进行迁移):

$.each(obj, function(key,value) {
   alert(value.com);
 });

Thanks 谢谢

I didn't find your jquery array in the codepen. 我没有在代码笔中找到您的jquery数组。
you should have an interval and loop through the array and show the results one by one. 您应该有一个间隔并遍历数组,并逐一显示结果。

your codes should be like this: 您的代码应如下所示:

var substr = ['hello','how are you?', 'what is your name?', 'have a good time'];
var x = -1;
setInterval(function() {
if (x < substr.length - 1){
x++;
substr[x]; 
$('.text').delay(2500).queue(function(next){            
$('.text').addClass('load');
$('.text').text(' ');
next(); 
});
$('.text').text(substr[x]);
$('.text').removeClass('load');  
}else{
x = -1;            
}            
}, 5000);

visit this codepen for a working example: 请访问此Codepen以获取工作示例:
https://codepen.io/nabilou/pen/EoJJPz https://codepen.io/nabilou/pen/EoJJPz

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

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