2011-07-12 88 views
0

我想做一個幻燈片,我剛開始玩網站和幻燈片不工作,我不知道爲什麼。我有固定的我,現在我需要一些幫助,這在所有的錯誤...Javascript幻燈片顯示一點幫助

<head> 
<title>Alanna's JavaScript slide show</title> 
<script language="JavaScript"> 

var interval = 1500; 
var random_display = 0; 
var imageDir = ""; 
var imageNum = 0; 
imageArray = new Array(); 
imageArray[imageNum++] = new imageItem(imageDir + "01.jpg"); 
imageArray[imageNum++] = new imageItem(imageDir + "02.jpg"); 
imageArray[imageNum++] = new imageItem(imageDir + "03.jpg"); 
imageArray[imageNum++] = new imageItem(imageDir + "04.jpg"); 
imageArray[imageNum++] = new imageItem(imageDir + "05.jpg"); 
var totalImages = imageArray.length; 
function imageItem(image_location) { 
    this.image_item = new Image(); 
    this.image_item.src = image_location; 
    function get_ImageItemLocation(imageObj) { 
     return (imageObj.image_item.src) 
    } 
    function randNum(x, y) { 
     var range = y - x + 1; 
     return Math.floor(Math.random() * range) + x; 
    } 
    function getNextImage() { 
     if (random_display) { 
      imageNum = randNum(0, totalImages - 1); 
     } 
     else { 
      imageNum = (imageNum + 1) % totalImages; 
     } 
     var new_image = get_ImageItemLocation(imageArray[imageNum]); 
     return (new_image); 
    } 
    function getPrevImage() { 
     imageNum = (imageNum - 1) % totalImages; 
     var new_image = get_ImageItemLocation(imageArray[imageNum]); 
     return (new_image); 
    } 
    function prevImage(place) { 
     var new_image = getPrevImage(); 
     document[place].src = new_image; 
    } 
    function switchImage(place) { 
     var new_image = getNextImage(); 
     document[place].src = new_image; 
     var recur_call = "switchImage('" + place + "')"; 
     timerID = setTimeout(recur_call, interval); 
    } 
<!-- 
// --> 
</script> 
</head> 

<body onLoad="switchImage('slideImg1')"> 

<img name="slideImg1" src="01.jpg" width=500 height=375 border=0> 
<img name="slideImg2" src="02.jpg" width=500 height=375 border=0> 
<img name="slideImg3" src="03.jpg" width=500 height=375 border=0> 
<img name="slideImg4" src="04.jpg" width=500 height=375 border=0> 
<img name="slideImg5" src="05.jpg" width=500 height=375 border=0> 


<a href="#" onClick="switchImage('slideImg1')">play slide show</a> 

<a href="#" onClick="clearTimeout(timerID)"> pause</a> 

<a href="#" onClick="prevImage('slideImg'); clearTimeout(timerID)"> previous</a> 

<a href="#" onClick="switchImage('slideImg2'); clearTimeout(timerID)">next </a> 

</body> 
+0

另外,擺脫腳本元素中的HTML註釋分隔符 - t嘿,大約15年或更長時間沒有必要(反正格式不正確)。 – RobG

回答

1

失蹤}

this.image_item.src = image_location; 
} <<<< 

有此一去這是我的猜測你想要什麼

<head> 
<title>Alanna's JavaScript slide show</title> 
<script language="JavaScript"> 
var interval = 1500; 
var random_display = 0; 
var imageDir = ""; 
var imageNum = 0; 
var imageArray = []; 
var place = "slideImg1"; 
for (var i=0;i<5;i++) { 
    imageArray[i] = new imageItem(imageDir + "0"+i+".jpg") 
} 
var totalImages = imageArray.length; 
function imageItem(image_location) { // preloads 
    this.image_item = new Image(); 
    this.image_item.src = image_location; 
}  
function get_ImageItemLocation(imageObj) { 
    return imageObj.image_item.src; 
} 
function randNum(x, y) { 
    var range = y - x + 1; 
    return Math.floor(Math.random() * range) + x; 
} 
function getNextImage() { 
    var imageNum = (random_display)?randNum(0, totalImages-1):(imageNum+1) % totalImages; 
    return get_ImageItemLocation(imageArray[imageNum]); 
} 
function getPrevImage() { 
    imageNum = (imageNum-1) % totalImages; 
    return get_ImageItemLocation(imageArray[imageNum]); 
} 
function prevImage() { 
    var new_image = getPrevImage(); 
    document[place].src = new_image; 
} 
function nextImage() { 
    var new_image = getNextImage(); 
    document[place].src = new_image; 
} 
window.onload=function() { 
    init(); 
} 
function init() { 
    nextImage() 
    timerID = setInterval(nextImage, interval); 
} 
</script> 
</head> 
<body> 
<img name="slideImg1" src="01.jpg" width=500 height=375 border=0> 
<a href="#" onClick="init()">play slide show</a> 
<a href="#" onClick="clearTimeout(timerID)"> pause</a> 
<a href="#" onClick="prevImage(); clearTimeout(timerID)">previous</a> 
<a href="#" onClick="nextImage(); clearTimeout(timerID)">next </a> 
</body> 
+0

非常感謝你是愚蠢的我哈哈,我的JS調試器甚至沒有顯示錯誤,使用鉻的JS控制檯 – Bulvak