-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
176 lines (153 loc) · 3.58 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>H5视频标签</title>
<style type="text/css">
.hide{
display: none;
}
.video{
width:600px;
height: 400px;
border:2px solid red;
margin:50px auto;
position: relative;
}
.video video{
display: block;
}
.skip{
display: block;
width:300px;
height: 200px;
background: url('images/ad.jpg');
z-index: 9999;
position: absolute;
top:50%;
left:50%;
margin: -100px 0 0 -150px;
cursor: pointer;
background-size: cover;
}
.toggle-btn{
display: block;
width: 70px;
height: 20px;
line-height: 20px;
border-radius: 10px;
border:2px solid #317ef3;
color:#317ef3;
position: absolute;
bottom: 38px;
right: 10px;
font-weight: bold;
text-align: center;
cursor: pointer;
font-size: 12px;
}
.toggle-btn:hover,.skip-adver:hover{
background-color: #317ef3;
color: #fff;
}
.skip-adver{
display: block;
width: 70px;
height: 20px;
line-height: 20px;
border-radius: 10px;
border:2px solid #317ef3;
color:#317ef3;
position: absolute;
top: 38px;
right: 10px;
font-weight: bold;
text-align: center;
cursor: pointer;
font-size: 12px;
}
.hide{
display: none !important;
}
.countdown{
display: block;
width: 100px;
height: 20px;
line-height: 20px;
border-radius: 10px;
border:2px solid #317ef3;
color:#fff;
position: absolute;
top: 38px;
right: 120px;
text-align: center;
cursor: pointer;
font-size: 12px;
background:#317ef3;
}
</style>
</head>
<body>
<div class="video">
<video id="media" controls="controls" width="600" height="400" autoplay>
<source src="video/adver.mp4" type="video/mp4" />
您的浏览器版本太低,请及时更新
</video>
<a href="http://www.baidu.com" target="_blank" class="skip"></a>
<!-- 切换清晰度 -->
<a class="toggle-btn hide">切换至240p</a>
<!-- 倒计时 -->
<a class="countdown">广告剩余<span></span>秒</a>
<!-- 跳过广告 -->
<a class="skip-adver">跳过广告</a>
</div>
<script src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
//定义广告结束播放视频的函数
function playVideo(){
$('.countdown').addClass('hide');
$('.skip-adver').addClass('hide');
$('.toggle-btn').removeClass('hide');
$("#media").attr("src","video/video.mp4").attr("autoplay","true");
}
//设置倒计时
window.onload=function(){
//获取广告的总时长
var video=document.getElementById("media");
videoTime=Math.floor(video.duration);
$('.countdown span').html(videoTime);
setInterval(function(){
videoTime--;
$('.countdown span').html(videoTime);
if(videoTime == 0){
playVideo();
}
},1000)
}
//跳过广告
$('.skip-adver').click(function(){
playVideo();
})
//控制广告图片的显示和隐藏
$('.skip').hide();
var myVideo=document.getElementById("media");
myVideo.addEventListener('play',function(){
$('.skip').hide();
});
myVideo.addEventListener('pause',function(){
$('.skip').show();
})
////切换清晰度(可设置多种清晰度,实质改变src即可)
function toggleVideo(e){
//当前播放时间
var curTime=e.currentTime;
$("#media").attr("src","video/240p.mp4").attr("autoplay","true");
//切换后的视频按照当前播放时间继续播放,而不是从头播放
e.currentTime=curTime
}
$('.toggle-btn').click(function(){
toggleVideo(myVideo);
})
</script>
</body>
</html>