2012-01-06 117 views
0

怎么可能用jquery each()逐个显示循环元素,比如有一个延迟?用jquery显示循环元素用一个一个来显示

function text_animate(){ 


    var get_text=$("#animated_text_falling h1").text(); 
    var words =get_text.split(" "); 
    $("#animated_text_falling h1").remove("h1"); 
    var wordCount = 0; 
     $.each(words, function(key, value) { 



    var $word= $('<div id= word_' + key + '>' + value + '</div>').appendTo('#animated_text_falling').show(); 

    //here somhow to show $('<div id= word_' + key + '>' + value + '</div>') with delay 

    wordCount++; 
    }); 

} 
+0

[Jquery的。每个()包括找干净的代码的延迟(可能重复http://stackoverflow.com/questions/4143308/jquery - 每一个 - 包括-A-延迟找换干净的代码) – Matt 2012-01-06 11:56:09

回答

0

尝试使用.delay()

function text_animate(){ 


    var get_text=$("#animated_text_falling h1").text(); 
    var words =get_text.split(" "); 
    $("#animated_text_falling h1").remove("h1"); 
    var wordCount = 0; 
    var delayCount = 0; 
     $.each(words, function(key, value) { 

delayCount = delayCount + 1000; 

    var $word= $('<div id= word_' + key + '>' + value + '</div>').appendTo('#animated_text_falling').delay(delayCount).show(); 

    //here somhow to show $('<div id= word_' + key + '>' + value + '</div>') with delay 

    wordCount++; 
    }); 

}