一、问题
1.默认播放按键不好看
2.设置自定义封面图
以上这两点都想自定义
二、思路
1.使用div把video标签盖住
2.div中显示自定义的海报图片与按钮
三、步骤分解
1.海报图片作为div的背景
注:无论是横图还是竖图,都希望按原比例显示在div内
css:
.yourDiv{ background-color: black; height:20em; background-image: url('./images/timg.jpg'); background-size: contain; background-repeat: no-repeat; background-position: center; }
html
<div class="yourDiv"></div>
效果
竖图:
横图:
2.插入自定义播放图标
css
.yourDiv { background-color: black; height:20em; background-image: url('./images/timg.jpg'); background-size: contain; background-repeat: no-repeat; background-position: center; display:flex; align-items: center; } .yourDiv img { width:20%; margin-left: 40%; }
html
<div class="yourDiv"> <img src="./images/play.png"> </div>
效果
3.把div覆盖到video标签上
css
.yourDiv { background-color: black; height:20em; background-image: url('./images/timg.jpg'); background-size: contain; background-repeat: no-repeat; background-position: center; display:flex; align-items: center; position: absolute; top: 0px; left: 0px; width: 100%; } .yourDiv img { width:20%; margin-left: 40%; } .father { background-color: black; width:100%; height:16em; position: relative; }
htm5
<div class="father"> <video id="video" controls="controls" autoplay="autoplay" style="width:100%;height:16em"> <source src="./videos/v1.mp4" type="video/ogg" /> <source src="./videos/v1.mp4" type="video/mp4" /> </video> <div class="yourDiv"> <img src="./images/play.png"> </div> </div>
4.触发播放方法
html
<div class="father"> <video id="video" controls="controls" autoplay="autoplay" style="width:100%;height:16em"> <source src="./videos/v1.mp4" type="video/ogg" /> <source src="./videos/v1.mp4" type="video/mp4" /> </video> <div id="poster" class="yourDiv" onclick="play()"> <img src="./images/play.png"> </div> </div>
js
var video = document.getElementById("video"); function play(){ document.getElementById("poster").style.display = "none"; video.play(); }
这样就达到了之前的目的
总结:关键的还是 :background-position: center;
以上所述是小编给大家介绍的html5自定义video标签的海报与播放按钮功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】
- 刘宇.2024-宇宙诗人【哔哟哔哟文化】【FLAC分轨】
- 《全景声白噪音》沉浸式大自然助眠 带你听自然的声音[mp3]
- 纯音入心系列纯音乐《古筝精选 十指弹一赏心曲一心奏出世人心》1CD[MP3][582MB]
- 纯音入心系列纯音乐《古筝与现代音乐的交织》1CD[MP3][96MB]
- 王俪婷.2011-ROMANCE【华研国际】【WAV+CUE】
- 狮子合唱团.2016-LION(引进版)【华纳】【WAV+CUE】