基于h5的video,很容易上手,直接上代码,其中还有一些可以优化的地方,大家可以自己优化
在这里插入代码片<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>视频播放器</title>
<style>
.video-box {
width: 800px;
margin: 0 auto;
position: relative;
}
.menu {
visibility: hidden;
position: absolute;
left: 130px;
bottom: 41px;
width: 120px;
display: flex;
justify-content: space-between;
font-size: 14px;
align-items: center;
}
#forward {
width: 24px;
height: 24px;
border: none;
background: url('./快进.svg') no-repeat;
cursor: pointer
}
#back {
width: 24px;
height: 24px;
border: none;
background: url('./快退.svg') no-repeat;
cursor: pointer;
}
.speed {
color: white;
cursor: pointer;
display: flex;
flex-direction: column;
}
ul {
list-style: none;
position: absolute;
bottom: 20px;
color: white;
background-color: black;
font-size: 14px;
width: 30px;
padding: 0;
margin: 0;
text-align: center;
display: none;
opacity: 0.8;
border-radius: 10px;
}
ul li{
padding: 2px;
}
.speed:hover ul {
display: block;
}
.video-box:hover .menu {
visibility: visible;
}
</style>
</head>
<body>
<div class="video-box">
<video src="./鸿联九五介绍视频.mp4" width="800px" controls poster="./鸿联九五介绍视频.jpg" ></video>
<div class="menu">
<div class="speed">
<ul class="speeds">
<li>0.5</li>
<li>1</li>
<li>1.5</li>
<li>2</li>
</ul>
<span>倍速</span>
</div>
<button id="back"></button>
<button id="forward"></button>
</div>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
var select = document.querySelector('select');
var add = document.getElementById("forward");
var Back = document.getElementById('back');
var video = document.querySelector('video');
//快进功能实现
add.onclick = function () {
//获取当前播放的时间
var now_time = video.currentTime;
//计算快进后的播放时间点
var new_time = now_time + 10;
//新值赋值回去
video.currentTime = new_time;
}
Back.onclick = function () {
//获取当前播放的时间
var now_time = video.currentTime;
//计算快进后的播放时间点
var new_time = now_time - 10;
//新值赋值回去
video.currentTime = new_time;
}
$("ul li").click(function () {
var item = $(this).index(); //获取索引下标 也从0开始
var textword = $(this).text(); //文本内容
video.playbackRate = textword
})
</script>
</body>
</html>
效果如下