2019-06-26 | video | UNLOCK

视频播放的相关问题

禁止默认全屏

1
<video src="https://vod.tthunbohui.cn/dmp/s/merchant/1536768000/test1.mp4" class="video-content" x5­-playsinline playsinline -webkit-playsinline></video>

自定义播放暂停

1
2
3
4
5
6
7
8
<div class="video-box">
<video src="https://vod.tthunbohui.cn/dmp/s/merchant/1536768000/test1.mp4" class="video-content"
webkit-playsinline x5­-video­-player­-fullscreen="false" playsinline -webkit-playsinline></video>
<img src="https://img.tthunbohui.cn/dmp/other/1526572800/jh-img-orig-ga_997441069850435584_640_425_406458.png"
alt="" srcset="" class="cover">
<img src="https://img.tthunbohui.cn/zhuanti/1024149/icon_play.png" alt="" srcset="" class="play">
<i class="iconfont icon-pause pause"></i>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* playClass:<String/> 代表播放时播放按钮的样式
* pauseClass:<String/> 代表暂停时播放按钮的样式
**/
function videoJs({
playClass = "playOne",
pauseClass = "pauseOne"
}) {
let videoArr = document.querySelectorAll(".video-content");
let coverArr = document.querySelectorAll(".cover");
let playArr = document.querySelectorAll(".play");
let pauseArr = document.querySelectorAll(".pause");
for (let index = 0; index < videoArr.length; index++) {
const videoElement = videoArr[index];
let coverTemp = coverArr[index];
let playTemp = playArr[index];
let pauseTemp = pauseArr[index];

playTemp.onclick = function () {
coverTemp.style.display = "none";
let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList);
let playTempClassList = Array.prototype.slice.call(playTemp.classList)
if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) {
pauseTemp.classList.remove(pauseClass);
}
if (playTempClassList.join(",").indexOf(playClass) > 0) {
playTemp.classList.remove(playClass);
}
pauseTemp.classList.add(pauseClass);
playTemp.classList.add(playClass);
videoElement.play();
}
pauseTemp.onclick = function () {
coverTemp.style.display = "inline-block";
let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList);
let playTempClassList = Array.prototype.slice.call(playTemp.classList)
if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) {
pauseTemp.classList.remove(pauseClass);
}
if (playTempClassList.join(",").indexOf(playClass) > 0) {
playTemp.classList.remove(playClass);
}
videoElement.pause();
}

videoElement.onended = function () {
coverTemp.style.display = "inline-block";
let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList);
let playTempClassList = Array.prototype.slice.call(playTemp.classList)
if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) {
pauseTemp.classList.remove(pauseClass);
}
if (playTempClassList.join(",").indexOf(playClass) > 0) {
playTemp.classList.remove(playClass);
}
}
}
}
videoJs({
playClass: "playOne",
pauseClass: "pauseOne"
})

评论加载中