怎么在html5中自定義video標(biāo)簽實(shí)現(xiàn)海報(bào)與播放按鈕功能?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括華州網(wǎng)站建設(shè)、華州網(wǎng)站制作、華州網(wǎng)頁(yè)制作以及華州網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,華州網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶(hù)以成都為中心已經(jīng)輻射到華州省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶(hù)的支持與信任!1.默認(rèn)播放按鍵不好看
2.設(shè)置自定義封面圖
以上這兩點(diǎn)都想自定義
1.使用div把video標(biāo)簽蓋住
2.div中顯示自定義的海報(bào)圖片與按鈕
1.海報(bào)圖片作為div的背景
注:無(wú)論是橫圖還是豎圖,都希望按原比例顯示在div內(nèi)
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.插入自定義播放圖標(biāo)
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標(biāo)簽上
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.觸發(fā)播放方法
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();
}
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。
當(dāng)前名稱(chēng):怎么在html5中自定義video標(biāo)簽實(shí)現(xiàn)海報(bào)與播放按鈕功能-創(chuàng)新互聯(lián)
文章URL:http://chinadenli.net/article8/ceseop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、定制開(kāi)發(fā)、品牌網(wǎng)站設(shè)計(jì)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、微信小程序、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容