JavaScriptを使用してインターバルタイマーを設定しようとすると、イメージを配列に配置する方法がわかりません。
私はいくつかの異なる方法を試しましたが、動作させることはできません。x秒ごとに新しい画像を表示するには?
var myImage = document.getElementById("mainImage");
var imageArray = [img class="irc_mi ix3z7xWjrSdc-pQOPx8XEepE" alt="Image result for baseball images" style="margin-top: 70px;" src="http://totalsportscomplex.com/wp-content/uploads/2014/09/baseball-pic.jpg" onload="google.aft&&google.aft(this)" width="626" height="415",
img class="irc_mi ix3z7xWjrSdc-pQOPx8XEepE" alt="Image result for baseball images" style="margin-top: 70px;" src="http://totalsportscomplex.com/wp-content/uploads/2014/09/baseball-pic.jpg" onload="google.aft&&google.aft(this)" width="626" height="415",
img class="irc_mi ix3z7xWjrSdc-pQOPx8XEepE" alt="Image result for baseball images" style="margin-top: 70px;" src="http://totalsportscomplex.com/wp-content/uploads/2014/09/baseball-pic.jpg" onload="google.aft&&google.aft(this)" width="626" height="415"]
var imageIndex = 0;
function changeImage() {
myImage.setAttribute("src",imageArray[imageIndex]);
imageIndex++;
if(imageIndex >= imageArray.length) {
indexImage = 0;
}
}
setInterval(changeImage,5000);
事前に感謝しています。また、私は新しく、答えを探してみましたが、見つからなかった。あなたの配列は、文字列の配列である必要があり
あなた 'imageArray'は有効な配列ではありません。基本的に '['と ']'の間には巨大な構文エラーがあります。あなたのコードに基づいて、配列内にソースを置くだけでよい: 'var imageArray = [" http://totalsportscomplex.com/wp-content/uploads/2014/09/baseball-pic.jpg "、" .. 。 "、" ... "];' –
そして 'imageIndex!== indexImage' – Andreas