Skip to content

Commit da79147

Browse files
committed
视频倍速播放
1 parent 523a46a commit da79147

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

‎视频倍速播放/index.html‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=
6+
, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>倍速播放</title>
9+
<style>
10+
body {
11+
margin: 0;
12+
display: flex;
13+
justify-content: center;
14+
align-items: center;
15+
min-height: 100vh;
16+
background-size: cover;
17+
font-family: sans-serif;
18+
}
19+
.wrapper {
20+
width: 850px;
21+
display: flex;
22+
}
23+
video {
24+
box-shadow: 0 0 1px 3px rgba(0, 0, 0, 0.1);
25+
}
26+
.speed {
27+
background: #efefef;
28+
flex: 1;
29+
display: flex;
30+
align-items: flex-start;
31+
margin: 10px;
32+
border-radius: 50px;
33+
box-shadow: 0 0 1px 3px rgba(0, 0, 0, 0.1);
34+
overflow: hidden;
35+
}
36+
.speed-bar {
37+
width: 100%;
38+
background: linear-gradient(-170deg, #2376ae 0%, #c16ecf 100%);
39+
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2);
40+
display: flex;
41+
align-items: center;
42+
justify-content: center;
43+
padding: 2px;
44+
color: white;
45+
height: 16.3%;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
<div class="wrapper">
51+
<video class="flex" width="765" height="430" src="./新闻.mp4" loop controls></video>
52+
<div class="speed">
53+
<div class="speed-bar">1×</div>
54+
</div>
55+
</div>
56+
</body>
57+
<script>
58+
// 获取三个元素
59+
const speed = document.querySelector('.speed');
60+
const bar = speed.querySelector('.speed-bar');
61+
const video = document.querySelector('.flex');
62+
63+
function handleMove(e) {
64+
const y = e.pageY - this.offsetTop;//获取鼠标现在位置在速率框中的位置
65+
const percent = y / this.offsetHeight;
66+
const min = 0.4;//设置最小速率为0.4
67+
const max = 4;//设置最小速率为4
68+
const height = Math.round(percent * 100) + '%';//取整
69+
const playbackRate = percent * (max - min) + min;
70+
bar.style.height = height;//设置显示高度
71+
bar.textContent = playbackRate.toFixed(2) + '×';
72+
video.playbackRate = playbackRate;//通过playbackRate属性改变播放速率
73+
}
74+
// 给鼠标添加移动事件
75+
speed.addEventListener('mousemove', handleMove);
76+
</script>
77+
</html>

‎视频倍速播放/新闻.mp4‎

21.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)