我想顯示一些單詞,然後當它完成時顯示完整的句子。
這個問題並不重要,我嘗試,它一起玩。不是一個接一個。
你們其中一個人可以向我解釋我做錯了什麼嗎?
function DisplayHdline(callback){
var str = "HELP STOP CRUELTY NOW.";
var spans = '<span>' + str.split(/\s+/).join(' </span><span>') + '</span>';
jQuery(spans).hide().appendTo('#vidheadline').each(function(i) {
jQuery(this).delay(2000 * i).fadeIn('fast').delay(1000).fadeOut(50);
});
callback();
}
function addComplete(){
jQuery('LOREM IPSUM DOLLOR').appendTo('#vidheadline').fadeIn();
//alert('Where is my sentence');
}
DisplayHdline(function(){
jQuery.when(this).done(addComplete());
});
//jQuery.when(DisplayHdline()).then(addComplete());
感謝
詩:我做了搜索,並試圖在這裏找到不同sollutions。但都具有相同的結果,所以顯然,我做錯了什麼
編輯:這是我結束了 功能typePlay(){VAR = actionStr「幫助停止NOW殘酷對待。」 var spans =''+ actionStr.split(/ \ s + /)。join('')+'';
function DisplayHdline(){
return jQuery(spans).hide().appendTo('#vidheadline').each(function(i) {
jQuery(this).delay(2000 * i).fadeIn('fast').delay(1000).fadeOut(50);
}).promise();
}
function addComplete(){
jQuery('#vidheadline').hide().append('<p id="completeHeadline">' +actionStr+'</p>').fadeIn();
}
DisplayHdline().done(addComplete);
}
window.setInterval(function typeTimer(){
jQuery('#vidheadline').empty();
typePlay();
}, 25000);
typePlay().done(typeTimer);
感謝 ;)
感謝您的解釋馬特,真的幫助。當我查看jQuery文檔時,我看到的幾個例子沒有.promise();我必須承認我對此很新穎。偉大到現在,當時和完成將需要諾言(); – user3750757