观看视频时,通常可以通过控制视屏下方的播放控件来调节视频的播放效果,接下来,制作一个包含视频播放控件的视频播放页面。本案例只需完成页面展示效果即可,按钮功能需通过引入JavaScript代码来实现。 练习目标 Ø 视频的插入方法。 Ø 复习盒子宽与高的使用方法。 Ø 复习导航栏的设置。 具体实现步骤如下: a) 具体实现步骤如下: b) 先设定一个大盒子,内部嵌套视频及播放控件。 c) 通过video元素插入视频。 d) 控件结构由无序列表定义,并设置li左浮动。 e) 定义文字样式等。
时间: 2024-02-24 10:55:55 浏览: 165
非常抱歉,我是一个语言模型AI,我无法展示页面效果。但是我可以提供一些代码供您参考:
HTML代码:
```
<div class="container">
<video src="your-video-url.mp4"></video>
<ul class="controls">
<li><button id="playpause">播放/暂停</button></li>
<li><button id="stop">停止</button></li>
<li><button id="mute">静音</button></li>
<li><button id="volinc">音量 +</button></li>
<li><button id="voldec">音量 -</button></li>
<li><button id="fs">全屏</button></li>
</ul>
</div>
```
CSS代码:
```
.container {
position: relative;
width: 640px;
height: 360px;
margin: 0 auto;
}
video {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
}
.controls {
position: absolute;
bottom: 10px;
left: 0;
width: 100%;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.controls li {
display: inline-block;
margin: 0 5px;
}
.controls button {
font-size: 16px;
background: #fff;
border: none;
padding: 10px;
cursor: pointer;
}
.controls button:hover {
background: #f2f2f2;
}
```
JavaScript代码:
```
var video = document.querySelector('video');
var playpause = document.getElementById('playpause');
var stop = document.getElementById('stop');
var mute = document.getElementById('mute');
var volinc = document.getElementById('volinc');
var voldec = document.getElementById('voldec');
var fs = document.getElementById('fs');
playpause.addEventListener('click', function() {
if (video.paused || video.ended) {
video.play();
playpause.innerHTML = '暂停';
} else {
video.pause();
playpause.innerHTML = '播放';
}
});
stop.addEventListener('click', function() {
video.currentTime = 0;
video.pause();
playpause.innerHTML = '播放';
});
mute.addEventListener('click', function() {
video.muted = !video.muted;
if (video.muted) {
mute.innerHTML = '取消静音';
} else {
mute.innerHTML = '静音';
}
});
volinc.addEventListener('click', function() {
alterVolume('+');
});
voldec.addEventListener('click', function() {
alterVolume('-');
});
function alterVolume(dir) {
var currentVolume = Math.floor(video.volume * 10) / 10;
if (dir === '+') {
if (currentVolume < 1) video.volume += 0.1;
}
else if (dir === '-') {
if (currentVolume > 0) video.volume -= 0.1;
}
}
fs.addEventListener('click', function() {
handleFullscreen();
});
function handleFullscreen() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
}
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)