所以我有一个带有一个 div 容器和一个按钮的简单页面,我希望用户能够点击按钮并将新视频加载到 div 中。
我总共有 8 个视频,页面从自动播放和循环播放的视频开始,然后如果用户点击页面底部的按钮,视频 2 被加载并自动播放和循环,直到他们再次点击该按钮加载视频 3.
希望这是有道理的!我敢肯定这很容易做到,但我知道这需要我几天的时间才能弄清楚!
任何帮助都会很棒!
这是我的代码,
<div id="vidBox">
<video width= "977" height= "721" src= "1.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>
</div>
$("#vidBox").empty().append( video width= "977" height= "721" src= "2.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay" );
$("#vidBox").empty().append( video width= "977" height= "721" src= "3.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay" );
$("#vidBox").empty().append( video width= "977" height= "721" src= "4.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay" );
etc etc etc
这是我的更新代码
<!DOCTYPE html>
<html>
<head>
<title>Video Player</title>
<script type="text/javascript">
$("document").ready(function () {
var vid1 = $("<video width= "977" height= "721" src= "1.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid2 = $("<video width= "977" height= "721" src= "2.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid3 = $("<video width= "977" height= "721" src= "3.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid4 = $("<video width= "977" height= "721" src= "4.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid5 = $("<video width= "977" height= "721" src= "5.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid6 = $("<video width= "977" height= "721" src= "6.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid7 = $("<video width= "977" height= "721" src= "7.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
var vid8 = $("<video width= "977" height= "721" src= "8.mp4" type= "video/mp4" loop= "loop" autoplay="autoplay"</video>");
});
</script>
<script>
window.myVids = ["1.mp4", "2.mp4", "3.mp4", "4.mp4", "5.mp4", "6.mp4", "7.mp4", "8.mp4"];
</script>
<script>
var currentIndex = 0;
var $video = $("#vidBox video");
$("#myButton").click(function() {
video.attr("src", myVids[++currentIndex]);
});
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="vidBox">Content for New Div Tag Goes Here</div>
<button id="myButton">Click Me</button>
</body>
</html>