html5指定视频的海报,科技常识:html5自定义video标签的海报与播放按钮功能

今天小编跟大家讲解下有关html5自定义video标签的海报与播放按钮功能 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了有关html5自定义video标签的海报与播放按钮功能 的相关资料,希望小伙伴们看了有所帮助。

一、问题

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

效果

竖图:

横图:

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

play.png

效果

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

play.png

4.触发播放方法

html

play.png

js

var video = document.getElementById("video");

function play(){

document.getElementById("poster").style.display = "none";

video.play();

}

这样就达到了之前的目的

总结:关键的还是 :background-position: center;

以上所述是小编给大家介绍的html5自定义video标签的海报与播放按钮功能 希望对大家有所帮助 如果大家有任何疑问请给我留言 小编会及时回复大家的。在此也非常感谢大家对爱蒂网站的支持!

如果你觉得本文对你有帮助 欢迎转载 烦请注明出处 谢谢!

来源:爱蒂网

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时候联系我们修改或删除,多谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值