-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle.js
More file actions
59 lines (57 loc) · 1.81 KB
/
toggle.js
File metadata and controls
59 lines (57 loc) · 1.81 KB
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
// 大视频的dom
let bigVideoList = [...document.querySelectorAll("#bigVideoList >video")];
// 小视频的dom
let videoList = [...document.querySelectorAll("#videoList >video")];
// 视频描述
let videoDesc = document.querySelector(".targetVideoDesc");
let videoDescList = [
'original image',
'texture with a maze-like style',
'texture featuring the natural curve of tree branches',
'floral and ornate pattern'
]
console.log(videoDesc);
// 起始视频下标
let startIndex = 0;
videoList.forEach((video, index) => {
// 添加点击事件
video.addEventListener("click", (e) => {
// 排他--大视频的切换效果
for (let bigVideo of bigVideoList) {
bigVideo.style.opacity = "0";
}
bigVideoList[index].style.opacity = "1";
// 小视频的选中效果
for (let smallVideo of videoList) {
smallVideo.classList.remove("selectSmallVideo");
}
video.classList.add("selectSmallVideo");
videoDesc.innerText = videoDescList[index]
// 当点击指令视频的时候,记录当前下标
setTimeout(() => {
startIndex = index;
}, 190);
});
// 播放完毕事件
video.addEventListener("timeupdate", () => {
var duration = video.duration; // 视频总时长
var currentTime = video.currentTime; //当前所在的时间段
if (index != startIndex) {
return;
}
// 当距离结束还有0.2s的时候:设置进行下一个视频的点击
if (currentTime >= duration - 0.2) {
setTimeout(() => {
// 在这里处理循环前的逻辑
startIndex++;
if (startIndex > 3) {
startIndex = 0;
}
videoList[startIndex].click();
}, 190);
}
});
});
window.addEventListener("DOMContentLoaded", () => {
videoList[0].click();
});