我有一個倒計時誰將顯示一個新的piture每5次>>它近似的工作,但在由10張圖片組成的數組的末尾,我不能停止倒計時+停下來顯示與調用clearInterval圖片...在JavaScript中,我沒有成功阻止我的循環clearIntereval setInterval
我的腳本
<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>
任何有關如何執行提高我的劇本的想法?
謝謝
奧利維爾
也許我錯過了,但我沒有看到' stopinter'函數在任何地方調用... – Kryten
點擊'stop'按鈕,調用'stopinter()'函數。 –
它應該停止在數組長度結束...停止按鈕是另一種方式停止,但我沒有寫過我的代碼... – Olive