2016-11-14 46 views
0

我有一個倒計時誰將顯示一個新的piture每5次>>它近似的工作,但在由10張圖片組成的數組的末尾,我不能停止倒計時+停下來顯示與調用clearInterval圖片...在JavaScript中,我沒有成功阻止我的循環clearIntereval setInterval

enter image description here

我的腳本

<script> 
     var myImage = document.getElementById ("mainImage"); 
     var imageArray = ["img/lunge.png", 
         "img/plank.png", 
         "img/push-up-and-rotation.png", 
         "img/push-up.png", 
         "img/side-plank-left.png", 
         "img/side-plank-right.png", 
         "img/squat.png", 
         "img/step-up-onto-chair.png", 
         "img/triceps-dip-on-chair.png", 
         "img/wall-sit.png"] 
     var imageIndex = 0; 
     $(document).ready(function() { 
      $('#submit').click(function() { 
       $('.timer').circularCountDown() 
       var inter = setInterval (changeImage, 5000); 
       function changeImage() { 
        myImage.setAttribute ("src", imageArray [imageIndex]); 
        document.getElementById("circle").innerHTML = ""; 
        imageIndex++; 
        if (imageIndex >= imageArray.length) { 
         imageIndex =0; 
         } 
        $('.timer').circularCountDown() 
        } 
       function stopinter() { 
        clearInterval (inter); 
       } 
      }) 
     }) 
    </script> 

任何有關如何執行提高我的劇本的想法?

謝謝

奧利維爾

+2

也許我錯過了,但我沒有看到' stopinter'函數在任何地方調用... – Kryten

+0

點擊'stop'按鈕,調用'stopinter()'函數。 –

+0

它應該停止在數組長度結束...停止按鈕是另一種方式停止,但我沒有寫過我的代碼... – Olive

回答

0
imageIndex++; 
if (imageIndex >= imageArray.length) { 
    stopinter(); 
} 
+0

對不起,我沒有看到這個答案。但最終我找到了另一種方式。我也會嘗試你的主張! ;-) 謝謝 – Olive

0

Finaly,我讓這個解決方案工作:

$('.timer').circularCountDown() 
        for (;i==10;i++) { 
         clearInterval (inter); 
        } 
相關問題