HTML5 video自定義視頻播放器

来源:https://www.cnblogs.com/chenyingying0/archive/2020/03/03/12405147.html
-Advertisement-
Play Games

效果圖: video.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>video</title> <style> *{margin:0;padding:0;list-style: none;} /* ...


效果圖:

video.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>video</title>
    <style>
        *{margin:0;padding:0;list-style: none;}
        /*body{background:#d0d8e9;}*/
        /*要麼不加position,如果加了則必須同時設置body和height高度為100%*/
        html,body{
            background:#d0d8e9;
            position: relative;
            height:100%;
        }
        .box{width:540px;height:332px;box-shadow:0 0 4px #d0d8e9;position: absolute;left:50%;top:50%;margin:-166px 0 0 -270px;}
        .videoNode{width:540px;height:305px;/*float佈局可以清除上下間的空隙*/float:left;background-color: #000;}
        .ctrNode{width:540px;height:27px;/*gif格式容量更小*/background:url(data/ctrl_bg.gif) repeat-x;float:left;}    
        .playNode{float:left;width:13px;height:15px;margin:6px 0 0 14px;/*png更清晰*/background:url(data/playbtn.png) no-repeat;cursor:pointer;}
        .pauseNode{float:left;width:13px;height:15px;margin:6px 0 0 14px;/*png更清晰*/background:url(data/pause.png) no-repeat;cursor:pointer;}

        /*時間進度條部分*/
        .processNode{width:260px;height:9px;background:url(data/ctrl_bg.gif) top repeat-x;margin:9px 0 0 14px;float:left;position: relative;}
        .processLeft{position: absolute;left:-2px;top:0;background:url(data/proleft.png) no-repeat;width:4px;height:9px;}
        .processRight{position: absolute;right:-2px;top:0;background:url(data/right_bg.png) no-repeat;width:4px;height:9px;}
        .processCircle{position: absolute;left:-8.5px;top:-3px;background:url(data/circle.png) no-repeat;width:17px;height:17px;cursor:pointer;z-index:5;}
        .lineNode{width:0%;height:100%;position: absolute;top:0;left:0;background:url(data/line_bg.png) repeat-x;}
        .lineRight{position: absolute;width:2px;height:7px;top:0;right:0;background:url(data/line_r_bg.png) no-repeat;}

        /*聲音進度條部分*/
        .timeNode{float:left;width:57px;height:10px;margin:9px 0 0 9px;}
        .timeNode span{float:left;line-height:10px;font-size:10px;color:#fff;}
        .volumeNode{width:19px;height:17px;float:left;margin:6px 10px 0 17px;background:url(data/volume.png) no-repeat;}
        .vProcessNode{width:61px;height:9px;/*background:url(data/probg.gif) top repeat-x;*/margin:9px 0 0 4px;float:left;position: relative;}
        .vLineNode{width:61px;height:100%;position: absolute;top:1px;left:0;background:url(data/line_bg.png) repeat-x;}
        .vLineRight{position: absolute;width:2px;height:7px;top:0;right:0;background:url(data/line_r_bg.png) no-repeat;}
        #vCircleNode{left:52px;}

        /*全屏部分*/
        .fullNode{width:13px;height:15px;background:url(data/full.png) no-repeat;margin:6px 0 0 40px;float:left;cursor:pointer;}
        .fullNode:hover{transform:scale(1.1);/*transition:all .5s;*/}
    </style>
</head>
<body>
    <div class="box">
        <video class="videoNode" src="data/imooc.mp4" poster="data/poster.jpg"></video>
        <div class="ctrNode">
            <!-- 聲音播放 -->
            <div class="playNode"></div>
            <!-- 時間調節 -->
            <div class="processNode">
                <div class="processLeft"></div>
                <div class="processRight"></div>
                <div class="processCircle" id="circleNode"></div>
                <!-- 真正的進度條 -->
                <div class="lineNode">
                    <div class="lineRight"></div>
                </div>
            </div>
            <!-- 時間顯示 -->
            <div class="timeNode">
                <span class="now">00:00</span>
                <span>-</span>
                <span class="all">00:00</span>
            </div>
            <div class="volumeNode"></div>
            <!-- 音量調節 -->
            <div class="vProcessNode">
                <div class="processLeft"></div>
                <div class="processRight"></div>
                <div class="processCircle" id="vCircleNode"></div>
                <!-- 真正的進度條 -->
                <div class="vLineNode">
                    <div class="vLineRight"></div>
                </div>
            </div>
            <!-- 全屏 -->
            <div class="fullNode"></div>
        </div>
    </div>

    <script>
        var playNode=document.getElementsByClassName("playNode")[0],
            videoNode=document.getElementsByClassName("videoNode")[0],
            fullNode=document.querySelector(".fullNode"),
            // 聲音顯示
            nowNode=document.querySelector(".now"),
            allNode=document.querySelector(".all"),
            // 時間進度條
            processNode=document.querySelector(".processNode"),
            lineNode=document.querySelector(".lineNode"),
            circleNode=document.querySelector("#circleNode"),
            processCircle=document.querySelector("#processCircle"),
            // 聲音進度條
            vProcessNode=document.querySelector(".vProcessNode"),
            vLineNode=document.querySelector(".vLineNode"),
            playState=true;

        // 播放暫停
        playNode.onclick=function(){
            //es6語法
            //註意:要切換的樣式一定要在初始樣式的下麵定義,否則無法進行覆蓋
            //this.classList.toggle("pauseNode");

            //傳統語法
            playState=!playState;
            if(playState){
                this.className="playNode";
                videoNode.pause();
            }else{
                this.className="pauseNode";
                videoNode.play();
            }
        }

        //全屏
        fullNode.onclick=function(){
            if(videoNode.webkitRequestFullscreen){
                videoNode.webkitRequestFullscreen();
            }else if(videoNode.mozRequestFullScreen){
                videoNode.mozRequestFullScreen();
            }else{
                videoNode.requestFullscreen();
            }
        }

        //時間顯示(解決時間初始的NaN問題)
        videoNode.addEventListener("canplay",function(){
            var duration=videoNode.duration;

            var aMin=toDou(parseInt(duration/60));
            var aSec=toDou(parseInt(duration%60));

            allNode.innerHTML=aMin+":"+aSec;
        },false);

        //視頻播放時,更新當前時間
        videoNode.addEventListener("timeupdate",function(){
            var curTime=videoNode.currentTime;

            var cMin=toDou(parseInt(curTime/60));
            var cSec=toDou(parseInt(curTime%60));

            nowNode.innerHTML=cMin+":"+cSec;

            //進度條運動
            lineNode.style.width=(curTime/videoNode.duration*100)+"%";
            circleNode.style.left=lineNode.offsetWidth-8.5+"px";
            
        },false);

        //時間格式轉換
        function toDou(time){
            return time<10?"0"+time:time;
        }

        //拖拽進度條
        circleNode.onmousedown=	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • mysqldump -h主機IP -u用戶名 -p密碼 -w "欄位名>=欄位值" 資料庫名 表名 > 文件路徑/文件名 註意: "欄位名>=欄位值" ,一定要用雙引號 參數 參數說明 --all-databases , -A 導出全部資料庫。 mysqldump -uroot -p --all-d ...
  • 我以前還沒接觸Redis的時候,聽到大數據組的小伙伴在討論Redis,覺得這東西好高端,要是哪天我們組也可以使用下Redis就好了,好長一段時間後,我們項目中終於引入了Redis這個技術,我用了幾下,感覺Redis也就那麼回事啊,不就是get set嗎?當我又知道Redis還有自增、自減操作,而且這 ...
  • 刪除hdfs ha namenode的正常方式是先禁用高可用,今天想試試直接刪除其中一個namenode,於是開始操作,結果剩下的NN無法啟動。 cm頁面報錯:“Nameservice testCluster has no SecondaryNameNode or High-Availability ...
  • 解決這個時把我嚇壞了!!! 報錯如下 register db Ping , Error 1698: Access denied for user 'root'@'localhost' shell mysql USE mysql; mysql UPDATE user SET plugin='mysql ...
  • 響應式網頁設計項目-CnBlogs用戶意見調查 https://codepen.io/yiyunpan// #技術堆棧 1. 使用HTML、JavaScript和CSS完成。這裡是純CSS做的 #內容 1. 使用了H5 語義化的標簽 2. 使用了H5 Form表單的特性 3. Selection/O ...
  • 一、動畫效果 1.過渡與動畫相類似,都需要三要素,那麼他們的區別在哪裡呢? ​答:過渡必須是人為的觸發才會執行動畫,動畫不需要人為的觸發就可以自動執行​動畫。 2.​相同點: (1)過度和動畫都是用來給元素添加動畫的;(2)過渡和動畫都是系統​新增的一些屬性;(3)過渡和動畫都需要滿足三要素才會有動 ...
  • /* * 隨機排序1 */ function mapRandom(arr) { for (var i = 0, len = arr.length; i < len; i++) { var a = parseInt(Math.random() * len); var temp = arr[a]; ar ...
  • audio主要支持的音頻格式: mp3 ogg wav <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>audio</title> </head> <body> <!-- 方法一 --> <audio con ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...