【发布时间】:2019-10-02 08:12:13
【问题描述】:
我正在尝试为我拥有的文本创建类别,并且我想要它,这样当随机视频播放并以红色显示时,我希望该类别中的任何文本(何时?)显示出来,如果它落在蓝色上,然后我希望该类别中的任何文本(如何?)显示等等......
代码如下:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" title="Default Styles"/>
<script>
var r_text = new Array();
r_text[0] = "How can we become more self-organised in the next sprint?";
r_text[1] = "How can we improve our productivity, increase our velocity?";
r_text[2] = "How can we get better in Transparency and Visibility of issues and challenges?";
r_text[3] = "How can our PO help us, to focus more on the sprint goal?";
r_text[4] = "How can our SM help us improve our delivery?";
r_text[5] = "How can we be more T-shaped in the next sprint?";
r_text[6] = "How should we celebrate our successes more?";
r_text[7] = "How can we reduce our cycle times?";
r_text[8] = "How can we make our daily scrum more effective?";
r_text[9] = "How can we improve our delivery flow by applying WIP Limit?";
r_text[10] = "How can we improve our collaboration?";
r_text[11] = "How can I help someone else in the next sprint?";
r_text[12] = "How can we improve our Sprint planning event?";
r_text[13] = "How can we demonstrate Scrum Value Courage more?";
r_text[14] = "How can we demonstrate Scrum Value Respect more?";
r_text[15] = "How can we demonstrate Scrum Value Focus more?";
r_text[16] = "How can we demonstrate Scrum Value Commitment more?";
r_text[17] = "How can we demonstrate Scrum Value Commitment more?";
r_text[18] = "How can we demonstrate Scrum Value Commitment more?";
r_text[19] = "How can we demonstrate Scrum Value Commitment more?";
r_text[20] = "How can we demonstrate Scrum Value Commitment more?";
var i = Math.floor(20*Math.random())
var videos = [{
id: 1,
url: "https://www.youtube.com/embed/ngUMyF9D9SQ?autoplay=1",
text: r_text[i]
},
{
id: 2,
url: "https://www.youtube.com/embed/r-l_gVPVylM?autoplay=1",
text: r_text[i]
},
{
id: 3,
url: "https://www.youtube.com/embed/6ukTzRjXcR0?autoplay=1",
text: r_text[i]
},
{
id: 4,
url: "https://www.youtube.com/embed/n5BXMNCTu8I?autoplay=1",
text: r_text[i]
},
{
id: 5,
url: "https://www.youtube.com/embed/JtwVmnMNaEY?autoplay=1",
text: r_text[i]
},
{
id: 6,
url: "https://www.youtube.com/embed/lAMgRaHP8Q4?autoplay=1",
text: r_text[i]
}
];
window.onload = function() {
function rollVideo(numberRand) {
let playerDiv = document.getElementById("random_player");
if (document.querySelector("iframe") !== null) {
document.querySelector("iframe").remove();
}
let player = document.createElement("IFRAME");
let randomVideoUrl = videos[numberRand].url;
player.setAttribute("width", "640");
player.setAttribute("height", "390");
player.setAttribute("src", randomVideoUrl);
playerDiv.appendChild(player);
document.getElementById("r_text").innerHTML = "";
document.getElementById("r_text").innerHTML = r_text[Math.floor(6*Math.random())];
}
document.getElementById("btn-roll").addEventListener("click", startRoll);
function startRoll() {
let currentNumber = Math.floor(Math.random() * videos.length);
rollVideo(currentNumber);
}
};
</script>
</head>
<div id="random_player">
<div id="r_text">
</div>
</div>
<button id="btn-roll">Roll</button>
</html>
【问题讨论】:
-
你所说的“落在红色上”是什么意思?
-
我的意思是,如果骰子在红色上滚动,那么我想要类别中的文本如何?出现
-
什么是“红色”?您是在谈论视频的内容还是什么?
-
在视频中是的,如果你运行代码你就会明白红色是什么
-
我正在尝试为我拥有的文本创建类别,然后如果视频选择蓝色,例如,我希望它从“何时”等类别中选择文本...
标签: javascript html css arrays