2017-05-30 33 views
0

我試圖運行連續循環的視頻幻燈片。我已經設置了基於div id的數組,但是我收到一條錯誤消息,指出索引未定義。下面是HTML:當我嘗試循環播放視頻數組時,未定義視頻陣列

<div id="div1" class="video"><video class="vidarray" src="icx.mp4"></video></div> 
<div id="div2" class="video"><video class="vidarray" src="icx2.mp4"></video></div> 
<div id="div3" class="video"><video class="vidarray" src="lastvid.mp4"></video></div> 

CSS:

div { 
height: 1080px; 
width: 1920px; 
display: none; 
} 

的jQuery:

var videos = [ 
'div1', 
'div2', 
'div3', 
] 
var videos = [ 
['div1' , 2000], 
['div2' , 2000], 
['div3' , 2000], 
] 

// Initate a counter at 1 because you're going to show the first video by default. 
var counter = 1; 
setInterval(function(){ 
// Hide all the video divs 
$(".video").hide(); 
// Show the video div based on the counter 
$('#'+ videos[counter][0]).show(); 
// Reset the video to the beginning 
$('video' +[counter]).load(); 
// Play the video 
$('video' + [counter]).play(); 

//Increment the counter if there are still more divs to show, otherwise reset it to 0 
counter == videos.length-1 ? counter = 0 : counter++;}, videos[counter][1]); 

負載(),這是jQuery的文檔中的問題......指數爲空.. 。

jQuery.fn.load = function(url, params, callback) { 
    var selector, type, response, 
    self = this, 
    off = url.indexOf(" "); 
+0

哪個索引沒有定義? – Taysumi

+0

第27行... $('#'+「video」+ [counter])。load(); – KevMoe

回答

0
var videos = [ 
["div1", 11000], 
["div2", 11000], 
["div3", 2000], 
] 

嘗試

var videos = [ 
    {"div1", 11000}, 
    {"div2", 11000}, 
    {"div3", 2000}, 
] 

還,因爲他們是你引用的ID,把#在前面:

示例 - $( '#' +視頻[窗口] [0])顯示();

+0

它說第27行... $('#'+「video」+ [counter])。load(); – KevMoe

+0

謝謝,但更改括號不起作用。我確實添加了'#'+,但它仍然不能識別索引。 – KevMoe