Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 每次进入网站时加载并洗牌视频_Javascript_Html_Twitter Bootstrap - Fatal编程技术网

Javascript 每次进入网站时加载并洗牌视频

Javascript 每次进入网站时加载并洗牌视频,javascript,html,twitter-bootstrap,Javascript,Html,Twitter Bootstrap,我一直在使用这个boostrap片段,它在进入网站时加载视频 我试图让它加载,并在每次你进入网站时随机列出视频列表,但我无法让它工作。请帮帮我 HTML: 最佳效果。我会保留一个视频URL数组,以及视频的各种选项,然后在加载页面时随机选择一个视频,并更新html的数据属性 Javascript: var vids = ["https://www.youtube.com/watch?v=fdJc1_IBKJA", "https://www.youtube.com/watch?v=xaDZvw9

我一直在使用这个boostrap片段,它在进入网站时加载视频

我试图让它加载,并在每次你进入网站时随机列出视频列表,但我无法让它工作。请帮帮我

HTML:


最佳效果。

我会保留一个视频URL数组,以及视频的各种选项,然后在加载页面时随机选择一个视频,并更新html的数据属性

Javascript:

var vids = ["https://www.youtube.com/watch?v=fdJc1_IBKJA",
  "https://www.youtube.com/watch?v=xaDZvw9ot3E",
  "https://www.youtube.com/watch?v=3WWlhPmqXQI"]; // create your list of youtube videos

var currVid = vids[Math.floor(Math.random()*(vids.length-1))]; // this will grab a random video from the array.

var opts = { // keep all the options in an object
  videoURL: currVid, // set the video to display
  containment:'.video-section',
  quality:'large', 
  autoPlay:true, 
  mute:true, 
  opacity:1
}

$(document).ready(function(){
  document.getElementById("bgndVideo").dataset.property = JSON.stringify(opts); // change to this

  $(".player").mb_YTPlayer(); // play!
});

希望这有帮助

我会保留一个视频URL数组,以及视频的各种选项,然后在加载页面时随机选择一个视频并更新html的数据属性

Javascript:

var vids = ["https://www.youtube.com/watch?v=fdJc1_IBKJA",
  "https://www.youtube.com/watch?v=xaDZvw9ot3E",
  "https://www.youtube.com/watch?v=3WWlhPmqXQI"]; // create your list of youtube videos

var currVid = vids[Math.floor(Math.random()*(vids.length-1))]; // this will grab a random video from the array.

var opts = { // keep all the options in an object
  videoURL: currVid, // set the video to display
  containment:'.video-section',
  quality:'large', 
  autoPlay:true, 
  mute:true, 
  opacity:1
}

$(document).ready(function(){
  document.getElementById("bgndVideo").dataset.property = JSON.stringify(opts); // change to this

  $(".player").mb_YTPlayer(); // play!
});

希望这有帮助

看一看:看一看:我需要对代码@hansstrausl的html部分做什么更改,质量:“大”,自动播放:真,静音:真,不透明度:1}“>bgYou不需要更新HTML,但是我更新了我的答案,似乎jQuery不会公开数据属性,所以我只使用普通的旧Javascript设置新属性。谢谢,现在它可以随机播放视频了!但有时每当我重新加载页面时,视频都不会播放:/Any tip?@RuiFarinha我才意识到又出现了一个错误,行
var currVid=vids[Math.floor(Math.random()*vids.length-1)]不正确,需要对
vids.length-1
进行偏执,因此下面是更正的行:
var currVid=vids[Math.floor(Math.random()*(vids.length-1))在代码@hansstrausl的html部分我需要更改什么,质量:“大”,自动播放:真,静音:真,不透明度:1}“>bgYou不需要更新HTML,但是我更新了我的答案,似乎jQuery不会公开数据属性,所以我只使用普通的旧Javascript设置新属性。谢谢,现在它可以随机播放视频了!但有时每当我重新加载页面时,视频都不会播放:/Any tip?@RuiFarinha我才意识到又出现了一个错误,行
var currVid=vids[Math.floor(Math.random()*vids.length-1)]不正确,需要对
vids.length-1
进行偏执,因此下面是更正的行:
var currVid=vids[Math.floor(Math.random()*(vids.length-1))
var vids = ["https://www.youtube.com/watch?v=fdJc1_IBKJA",
  "https://www.youtube.com/watch?v=xaDZvw9ot3E",
  "https://www.youtube.com/watch?v=3WWlhPmqXQI"]; // create your list of youtube videos

var currVid = vids[Math.floor(Math.random()*(vids.length-1))]; // this will grab a random video from the array.

var opts = { // keep all the options in an object
  videoURL: currVid, // set the video to display
  containment:'.video-section',
  quality:'large', 
  autoPlay:true, 
  mute:true, 
  opacity:1
}

$(document).ready(function(){
  document.getElementById("bgndVideo").dataset.property = JSON.stringify(opts); // change to this

  $(".player").mb_YTPlayer(); // play!
});