2013-11-26 35 views
0

我想循環下面的代碼。我搜索,但我沒有找到解決方案。有人能幫助我嗎?FadeIn FadeOut with Loop

<script> 


$(function(){ 
$('img#picture').fadeIn('slow'); 

setTimeout(function(){ 
    $('#test').fadeIn("slow"); 
}, 2000); 

setTimeout(function(){ 
$('#test').fadeOut("slow"); 
}, 10000); 


}) 

</script> 

非常感謝。

問候

+1

什麼是你想達到什麼目的? – Shyju

+0

我想循環整個腳本。首先淡化圖像,然後淡入淡出時間延遲的div。當一切都運行時,我想循環。非常感謝你。 – desmeit

回答

1

謝謝你給我看的網站,請試試這個:

<script> 
$(function(){ 

    $('img#jana, img#katharina, img#kathrin').fadeIn('slow', function() { 

     setTimeout(showNext, 2000); 

     setInterval(showNext, 10000); 

    }); 

    function showNext() { 
     var target = $('#expertenbilder'); 

     if (target.find('#sprechblase_jana').is(':visible')) { 
      $(this).fadeOut("slow"); 

      setTimeout(function() { 
       target.find('#sprechblase_katharina').fadeIn("slow"); 
      }, 2000); 
     } else if (target.find('#sprechblase_katharina').is(':visible')) { 
      $(this).fadeOut("slow"); 

      setTimeout(function() { 
       target.find('#sprechblase_kathrin').fadeIn("slow"); 
      }, 2000); 
     } else if (target.find('#sprechblase_kathrin').is(':visible')) { 
      $(this).fadeOut("slow"); 

      setTimeout(function() { 
       target.find('#sprechblase_jana').fadeIn("slow"); 
      }, 2000); 
     } else { 
      $('#sprechblase_jana').fadeIn("slow"); 
     } 
    } 

}); 
</script> 
+0

非常感謝,但這是不幸的,不工作。該腳本正在工作,但沒有循環。最好的問候 – desmeit

+0

它應該工作,你想達到什麼目的?也許我不明白你的問題。 – MonkeyZeus

+0

我想循環整個腳本。首先淡化圖像,然後淡入淡出時間延遲的div。當一切都運行時,我想循環。非常感謝你。 – desmeit

1

使用setInterval

var t=setInterval(function(){ 

$('img#picture').fadeIn('slow'); 

setTimeout(function(){ 
$('#test').fadeIn("slow"); 
}, 2000); 

setTimeout(function(){ 

    $('#test').fadeOut("slow"); 
}, 10000); 

},3000) //3000 is just an example, set suitable interval to allow effect to run smoothly 


window.clearInterval(t) //to stop 
+0

非常感謝。但不幸的是,它不工作。當我只寫入沒有「var t =」的setInterval時,它正在工作,但不是第一段。它只在第二段時纔有效。最好的祝福 – desmeit