自定义进度条

1、video标签是内联块,可以设置宽高,但是需要用大盒子将其包裹起来进行定位

2、小盒子设计成进度条样式,并进行定位

3、进度条样式中的特殊按钮可以用web字体

4、通过点击实现视频的暂停/播放 改变按钮的样式

5、获取视频的总时长,放到totalTime中

6、当视频播放的时候, 动态谁知crrTime的值,并且改变进度条的样式

7、实现全屏效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/font-awesome.css">
<style>
* {
padding: 0;
margin: 0;
} figcaption {
text-align: center;
font-size: 40px;
margin: 50px auto;
} .player {
width: 720px;
height: 360px;
margin: 100px auto;
background-color: #000;
position: relative;
} video {
display: block;
margin: 0 auto;
height: 100%;
} .control {
width: 700px;
height: 40px;
position: absolute;
background-color: rgba(63, 141, 56, 0.5);
bottom: 10px;
left: 10px;
border-radius: 10px;
} .switch {
position: absolute;
width: 40px;
height: 40px;
left: 10px;
top: 0;
font-size: 20px;
line-height: 40px;
text-align: center;
} .progress {
position: absolute;
width: 460px;
height: 10px;
left: 60px;
top: 15px;
background-color: rgba(255, 255, 255, 0.4);
border-radius: 5px;
} .curr-progress {
width: 0px;
height: 100%;
background-color: rgba(255, 255, 255, 1);
border-radius: 10px;
} .time {
position: absolute;
height: 40px;
right: 60px;
top: 0px;
font: 400 12px/40px "simsun";
text-align: center;
color: white;
} .extend {
position: absolute;
top: 0;
right: 5px;
width: 40px;
height: 40px;
text-align: center;
line-height: 40px;
}
</style>
</head>
<body>
<figure>
<figcaption>视频</figcaption>
<div class="player">
<video src="video/movie.mp4"></video>
<div class="control">
<span class="switch icon-play"></span>
<div class="progress">
<div class="curr-progress"></div>
</div>
<div class="time">
<span class="curr-time">00:00:00</span>/<span class="total-time">00:00:00</span>
</div>
<!-- 全屏-->
<span class="extend icon-resize-full"></span>
</div>
</div>
</figure>
<script>
var player = document.querySelector(".player");
var video = document.querySelector("video");
var swt = document.querySelector(".switch");
var extend = document.querySelector(".extend");
//通过点击 实现 视频的暂停/播放 改变按钮的样式
swt.onclick = function () {
if (video.paused) {
video.play();
player.style.backgroundImage = "url()";
swt.classList.remove("icon-play");
swt.classList.add("icon-pause");
}
else {
video.pause();
swt.classList.remove("icon-pause");
swt.classList.add("icon-play");
}
}
var totalTime = 0;
var currTime = 0;
//获取视频的总时长,放到totalTime中
video.oncanplay = function (ev) {
totalTime = video.duration;
var h = Math.floor(totalTime / 3600);
var m = Math.floor(totalTime % 3600 / 60);
var s = Math.floor(totalTime % 3600 % 60);
h = h >= 10 ? h : "0" + h;
m = m >= 10 ? h : "0" + m;
s = s >= 10 ? s : "0" + s;
document.querySelector(".total-time").innerHTML = h + ":" + m + ":" + s;
}
video.ontimeupdate = function (ev) {
currTime = video.currentTime;
var h = Math.floor(currTime / 3600);
var m = Math.floor(currTime % 3600 / 60);
var s = Math.floor(currTime % 3600 % 60);
h = h >= 10 ? h : "0" + h;
m = m >= 10 ? h : "0" + m;
s = s >= 10 ? s : "0" + s;
document.querySelector(".curr-time").innerHTML = h + ":" + m + ":" + s;
var xishu = totalTime / currTime;
document.querySelector(".curr-progress").style.width = (460 / xishu) + "px";
}
extend.onclick = function () {
video.webkitRequestFullScreen();
}
</script>
</body>
</html>

最新文章

  1. hihocoder #1341 Constraint Checker
  2. static方法中为什么使用的都是静态变量
  3. 实用的ajaxfileupload插件
  4. 服务器网站报错:由于扩展配置问题无法提供您请求的页面,请添加MIME映射,针对mp4,flv文件类型无法打开。
  5. Ext4.2 grid 条件查询使用
  6. 双MIC安卓手机录音问题
  7. vijos 1464 NOIP 1997 积木游戏
  8. linux在构建SVNserver
  9. 微信小程序(有始有终,全部代码)开发--- 新增【录音】以及UI改进
  10. POJ 1721 CARDS
  11. Activation error occured while trying to get instance of type Database,key &quot;&quot;之Oracle
  12. LeetCode算法题-Best Time to Buy and Sell Stock II
  13. [dpdk] SDK编译-简单扼要版
  14. Oracle 12c Sharding测试过程中的问题解决
  15. 多线程通信(wait和notify)
  16. Django具体操作(六)
  17. Android学习笔记——log无法输出的解决方法和命令行查看log日志
  18. [转]Format a ui-grid grid column as currency
  19. Linux中涉及到环境变量的文件
  20. 9、在Shell脚本中调用其他脚本

热门文章

  1. codeforces gym 100357 K (表达式 模拟)
  2. Ubuntu 16.04下没有“用户和组”功能的问题解决
  3. 从头认识java-15.1 填充容器(1)-利用Collection构造器的方式
  4. Scope Is the Enemy of Success
  5. UVA 23 out of 5
  6. InnoDB: Error: log file .\ib_logfile0 is of different size 0 10485760 bytes
  7. Android Application Digital Signatures - Android 数字签名
  8. 【POJ 2777】 Count Color(线段树区间更新与查询)
  9. WCF问题集锦:ReadResponse failed: The server did not return a complete response for this request.
  10. canvas上的像素操作(图像复制,细调)