欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Javascript實(shí)現(xiàn)視頻文件播放功能(示例詳解)

 更新時(shí)間:2023年10月11日 11:21:15   作者:Meteor.792  
這篇文章主要介紹了Javascript實(shí)現(xiàn)視頻文件播放功能,使用CSS完成相應(yīng)的布局樣式,利用JavaScript函數(shù)來監(jiān)聽進(jìn)度條,然后使用鼠標(biāo)點(diǎn)擊按鈕實(shí)現(xiàn)對(duì)視頻的播放,需要的朋友可以參考下

應(yīng)用CSS基礎(chǔ)和JavaScript的函數(shù)功能,制作一個(gè)視頻播放器。使用CSS完成相應(yīng)的布局樣式,利用JavaScript函數(shù)來監(jiān)聽進(jìn)度條,然后使用鼠標(biāo)點(diǎn)擊按鈕實(shí)現(xiàn)對(duì)視頻的播放。

CSS部分:

<style>
        * {
            margin: 0;
            padding: 0;
        }
        .body{
            height: 100%;
            width: 100%;
            background-image: url(風(fēng)景.jpg);
            position: fixed;
        }
        figcaption {
            text-align: center;
            font-family: "Microsoft YaHei";
            font-size: 24px;
            font-weight: 700;
            line-height: 150px;
        }
        .player {
            width:640px;
            height:360px;
            margin: 10px auto;
            background-color: pink;
            background:url("login_on.gif")
            top center no-repeat;
            background-size: auto 100%;
            position: relative;
            border-radius: 10px;
            overflow: hidden;
        }
        .player video {
            height:100%;
            display: block;
            margin: 0px auto;
            display: block;
        }
        .controls {
            width: 620px;
            height:40px;
            background-color: black;
            position: absolute;
            left: 10px;
            bottom: 10px;
            border-radius: 10px;
        }
        .switch {
            width: 20px;
            height: 20px;
            position: absolute;
            top:10px;
            left: 10px;
            display: block;
            text-align: center;
            line-height: 20px;
            color: yellow;
        }
        .progerss {
            width: 400px;
            height:10px;
            position: absolute;
            background-color:beige;
            left: 40px;
            top:15px;
            border-radius: 4px;
            overflow: hidden;
        }
        .cur-progress {
            width:0%;
            height:100%;
            background: yellow;
        }
        .time {
            width: 120px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            position: absolute;
            left: 450px;
            top:10px;
            font-size: 12px;
            color: #fff;
        }
        .exted {
            width: 20px;
            height: 20px;
            position: absolute;
            top:10px;
            right: 10px;
            text-align: center;
            line-height: 20px;
            color: yellow;
        }
    </style>
<style>
        * {
            margin: 0;
            padding: 0;
        }
        .body{
            height: 100%;
            width: 100%;
            background-image: url(風(fēng)景.jpg);
            position: fixed;
        }
        figcaption {
            text-align: center;
            font-family: "Microsoft YaHei";
            font-size: 24px;
            font-weight: 700;
            line-height: 150px;
        }
        .player {
            width:640px;
            height:360px;
            margin: 10px auto;
            background-color: pink;
            background:url("login_on.gif")
            top center no-repeat;
            background-size: auto 100%;
            position: relative;
            border-radius: 10px;
            overflow: hidden;
        }
        .player video {
            height:100%;
            display: block;
            margin: 0px auto;
            display: block;
        }
        .controls {
            width: 620px;
            height:40px;
            background-color: black;
            position: absolute;
            left: 10px;
            bottom: 10px;
            border-radius: 10px;
        }
        .switch {
            width: 20px;
            height: 20px;
            position: absolute;
            top:10px;
            left: 10px;
            display: block;
            text-align: center;
            line-height: 20px;
            color: yellow;
        }
        .progerss {
            width: 400px;
            height:10px;
            position: absolute;
            background-color:beige;
            left: 40px;
            top:15px;
            border-radius: 4px;
            overflow: hidden;
        }
        .cur-progress {
            width:0%;
            height:100%;
            background: yellow;
        }
        .time {
            width: 120px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            position: absolute;
            left: 450px;
            top:10px;
            font-size: 12px;
            color: #fff;
        }
        .exted {
            width: 20px;
            height: 20px;
            position: absolute;
            top:10px;
            right: 10px;
            text-align: center;
            line-height: 20px;
            color: yellow;
        }
    </style>

HTML部分:

<body class="body">
     <figure>
        <figcaption>視頻播放</figcaption>
        <div class="player">
            <video src="商丘古城--夜景.mp4"></video>
            <div class="controls">
                <a href="#" rel="external nofollow"  rel="external nofollow"  class="switch icon-play" title="播放"></a>
                <div class="progerss">
                    <div class="cur-progress"></div>
                </div>
                <div class="time">
                    <span class="curr-time">00:00:00</span>/
                    <span class="total-time">00:00:00</span>
                </div>
                <a href="#" rel="external nofollow"  rel="external nofollow"  class="exted icon-fullscreen" title="全屏"></a>
            </div>
        </div>
    </figure>
</body>

Javascript部分:

<script>
        var video = document.querySelector("video")
        var playBtn = document.querySelector(".switch");
        var crrProgress = document.querySelector(".cur-progress");
        var crrTime = document.querySelector(".curr-time");
        var totalTime = document.querySelector(".total-time");
        var exted = document.querySelector(".exted");
        var tTime;
        var cTime;
        playBtn.onclick = function () {
            if(video.paused){
                video.play();
                this.classList.remove("icon-play");
                this.classList.add("icon-pause");
                playBtn.title = "暫停";
            }else{
                video.pause();
                this.classList.remove("icon-pause");
                this.classList.add("icon-play");
                playBtn.title = "播放";
            }
        }
        video.oncanplay = function () {
            tTime = video.duration;
            var h = Math.floor(tTime / 3600);
            var m = Math.floor(tTime % 3600 / 60);
            var s = Math.floor(tTime % 60);
            h = h >= 10 ? h :"0" + h;
            m = m >= 10 ? m :"0" + m;
            s = s >= 10 ? s :"0" + s;
            totalTime.innerHTML = h + ":" + m + ":" + s;
        }
        video.ontimeupdate = function () {
            cTime = video.currentTime;
            var h = Math.floor(cTime / 3600);
            var m = Math.floor(cTime % 3600 / 60);
            var s = Math.floor(cTime % 60);
            h = h >= 10 ? h :"0" + h;
            m = m >= 10 ? m :"0" + m;
            s = s >= 10 ? s :"0" + s;
            crrTime.innerHTML = h + ":" + m + ":" + s;
            var value = cTime / tTime;
            crrProgress.style.width = value * 100 + "%";
        }
        exted.onclick = function () {
            video.webkitRequestFullScreen();
        }
</script>

效果圖:

JavaScript介紹:

        JavaScript(簡(jiǎn)稱“JS”) 是一種具有函數(shù)優(yōu)先的輕量級(jí),解釋型或即時(shí)編譯型的編程語言。雖然它是作為開發(fā)Web頁(yè)面的腳本語言而出名,但是它也被用到了很多非瀏覽器環(huán)境中,JavaScript 基于原型編程、多范式的動(dòng)態(tài)腳本語言,并且支持面向?qū)ο蟆⒚钍?、聲明式、函?shù)式編程范式。

        JavaScript在1995年由Netscape公司的Brendan Eich,在網(wǎng)景導(dǎo)航者瀏覽器上首次設(shè)計(jì)實(shí)現(xiàn)而成。因?yàn)镹etscape與Sun合作,Netscape管理層希望它外觀看起來像Java,因此取名為JavaScript。但實(shí)際上它的語法風(fēng)格與Self及Scheme較為接近。

        JavaScript的標(biāo)準(zhǔn)是ECMAScript 。截至 2012 年,所有瀏覽器都完整的支持ECMAScript 5.1,舊版本的瀏覽器至少支持ECMAScript 3 標(biāo)準(zhǔn)。2015年6月17日,ECMA國(guó)際組織發(fā)布了ECMAScript的第六版,該版本正式名稱為 ECMAScript 2015,但通常被稱為ECMAScript 6 或者ES2015。

JavaScript腳本語言具有以下特點(diǎn):

(1)腳本語言。JavaScript是一種解釋型的腳本語言,C、C++等語言先編譯后執(zhí)行,而JavaScript是在程序的運(yùn)行過程中逐行進(jìn)行解釋。

(2)基于對(duì)象。JavaScript是一種基于對(duì)象的腳本語言,它不僅可以創(chuàng)建對(duì)象,也能使用現(xiàn)有的對(duì)象。

(3)簡(jiǎn)單。JavaScript語言中采用的是弱類型的變量類型,對(duì)使用的數(shù)據(jù)類型未做出嚴(yán)格的要求,是基于Java基本語句和控制的腳本語言,其設(shè)計(jì)簡(jiǎn)單緊湊。

(4)動(dòng)態(tài)性。JavaScript是一種采用事件驅(qū)動(dòng)的腳本語言,它不需要經(jīng)過Web服務(wù)器就可以對(duì)用戶的輸入做出響應(yīng)。在訪問一個(gè)網(wǎng)頁(yè)時(shí),鼠標(biāo)在網(wǎng)頁(yè)中進(jìn)行鼠標(biāo)點(diǎn)擊或上下移、窗口移動(dòng)等操作JavaScript都可直接對(duì)這些事件給出相應(yīng)的響應(yīng)。

(5)跨平臺(tái)性。JavaScript腳本語言不依賴于操作系統(tǒng),僅需要瀏覽器的支持。因此一個(gè)JavaScript腳本在編寫后可以帶到任意機(jī)器上使用,前提是機(jī)器上的瀏覽器支 持JavaScript腳本語言,JavaScript已被大多數(shù)的瀏覽器所支持。 不同于服務(wù)器端腳本語言,例如PHP與ASP,JavaScript主要被作為客戶端腳本語言在用戶的瀏覽器上運(yùn)行,不需要服務(wù)器的支持。所以在早期程序員比較傾向于使用JavaScript以減少對(duì)服務(wù)器的負(fù)擔(dān),而與此同時(shí)也帶來另一個(gè)問題,安全性。

到此這篇關(guān)于Javascript實(shí)現(xiàn)視頻文件播放功能的文章就介紹到這了,更多相關(guān)js視頻文件播放內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論