亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么用JavaScript實現網頁視頻添加水印

發布時間:2022-02-15 16:26:06 來源:億速云 閱讀:252 作者:iii 欄目:開發技術

這篇“怎么用JavaScript實現網頁視頻添加水印”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“怎么用JavaScript實現網頁視頻添加水印”文章吧。

原理

通過html的頁面布局,在video播放器層面,通過js控制dom,插入文本水印代碼。

代碼示例

index.html

<!DOCTYPE html>
<html>
<head>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>html5視頻水印</title>
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
  <link rel="stylesheet" type="text/css" href="css/waterMarkVideo.css" rel="external nofollow" >
</head>
<body>
  <div id="container">
            <div >
              <div class="watermark video-watermark-multiple video-watermark-item">
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
              <div class="noselect"><span class="span"><span></div>
            </div>
             <video width="640px" height="360px">
                 <source src="https://blz-videos.nosdn.127.net/1/OverWatch/AnimatedShots/Overwatch_TheatricalTeaser_WeAreOverwatch_zhCN.mp4" type="video/mp4"/>
             </video>
             <div class="pos">
                 <img src=" img/i-play.png" width="40px" id="playBtn" />
                 <div >
                     <progress  value="0" id="progress"></progress>
                 </div>
                 <div class="timebox">
                     <span id="time1">
                         00:00:00
                     </span>/
                     <span id="time2">
                         00:00:00
                     </span>
                 </div>
                 <img src="img/i-fs.png" width="35px" id="full"/>
            </div>
         </div>
  </div> 
<script type="text/javascript">
    $(".span").html("water-mark");
    var video = document.querySelector("video");
    var playBtn = document.getElementById("playBtn");
    playBtn.onclick = function(){
        if(video.paused){
            video.play();
            playBtn.src = "img/i-pause.png";
        }else{
            video.pause();
            playBtn.src = "img/i-play.png";
       }
    }
    var full = document.getElementById("full");
    var container = document.getElementById("container");
    var i = 1;//定義一個變量,用于記錄是否為全屏狀態
    full.onclick = function(){
       i++;//對2取余,為0則全屏,否則關閉全屏
       if(i%2==0){//點擊開啟全屏
           if(container.requestFullScreen){
                container.requestFullScreen()
           }else if(container.webkitRequestFullScreen){
                container.webkitRequestFullScreen()//谷歌
           }else if(container.mozRequestFullScreen){
                container.mozRequestFullScreen()//火狐
           }else if(container.msRequestFullscreen){
                container.msRequestFullscreen()//ie
           }
           $('video').css({"width":"100%","height":"100%"});
           $(".pos").css("width","100%");
           full.src = "img/i-exitfs.png";
       }else{//關閉全屏
           if(document.cancelFullscreen){
                document.cancelFullscreen();
           }else if(document.webkitCancelFullScreen){
                document.webkitCancelFullScreen();
           }else if(document.mozCancelFullScreen){
                document.mozCancelFullScreen();
           }else if(document.msExitFullscreen){
                document.msExitFullscreen();
           }
           $('video').css({"width":"640px","height":"360px"});
           $(".pos").css("width","640px");
           full.src = "img/i-fs.png";
       }
        
    }
    function number1(s){
            if(s<10){
                s="0"+s
            }else{
                s=""+s
            }
            return s;
    }
    var time1 = document.getElementById("time1");
    var time2 = document.getElementById("time2");
    var t1;
     //視頻獲取時間單位為秒,要對它進行一些數據的處理
    video.oncanplay = function(){  
         t1 = video.duration;//獲取視頻總時長
         var h = parseInt(t1/3600);
         var m = parseInt(t1%3600/60);
         var s = parseInt(t1%60);    
         time2.innerHTML = number1(h) + ":"+ number1(m) + ":" + number1(s);//值顯示在span標簽中
     }
     //獲取當前視頻播放的時間
    video.ontimeupdate = function(){
         var t2 = video.currentTime;
         var h = parseInt(t2/3600);
         var m = parseInt(t2%3600/60);
         var s = parseInt(t2%60);
         time1.innerHTML = number1(h) + ":"+ number1(m) + ":" + number1(s);
         progress.max = t2;
         progress.value = t2/t1*progress.max;
    }
    video.onended = function(){
        progress.value = 0;     
        time1.innerHTML = "00"+":"+"00"+":"+"00";//播放結束時時間清0;
        playBtn.src = "img/i-play.png";//播放結束時按鈕恢復
    }
              
    progress.onclick = function(e){
          //獲取當前位置距離父級最左邊的距離
          //left = progress.offsetLeft;
          //獲取鼠標距離屏幕最左邊的距離
          //e.clientX
          //獲取鼠標距離當前元素最左邊的距離
           var left  = e.offsetX;
           console.log(left);
           console.log(t1);
           video.currentTime = left/360*t1;
    }
</script>
</body>
</html>

核心代碼

$(".span").html("water-mark");

"water-mark"字段添加要打的水印內容。也可以動態添加水印內容。

樣式waterMarkVideo.css代碼

body,div,img{
    margin: 0;
    padding: 0;
    border: 0;
}
#container{
    width: 640px;
   border: 1px solid pink;
}
.pos{
   width: 640px;
   height: 60px;
   background: rgba(0,0,0,0.5);
   margin-top: -63px;
   position: relative;
   
}
#playBtn{
   position:relative;
   top: 10px;
   left: 20px;
   cursor: pointer;
}
#progress{
   height: 12px;
   width: 100%;
   position: relative;
   top: -27px;
   cursor: pointer;
   
}
.timebox{
   position:absolute;
   top: 20px;
   right: 80px;
   cursor: pointer;
   color: white;
}
#full{
   position:absolute;
   top: 12px;
   right: 20px;
   cursor: pointer;
}
.video-watermark-item {
    left: 15%;
    top: 10%;
    font-size: 20px;
    color: rgba(240,240,240,0.3);
    font-family: 方正黑體;
    -o-transform: translate(-15%, -50%) rotate(-35deg);
    -webkit-transform: translate(-15%, -50%) rotate(-35deg);
    -moz-transform: translate(-15%, -50%) rotate(-35deg);
    -ms-transform: translate(-15%, -50%) rotate(-35deg);
    transform: translate(-15%, -50%) rotate(-35deg);
    position: absolute;
    overflow: hidden;
}
.noselect {
  display: inline-block;
  padding: 100px;
}

以上就是關于“怎么用JavaScript實現網頁視頻添加水印”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

探索| 威远县| 巧家县| 苍南县| 博野县| 且末县| 德保县| 微博| 阜阳市| 广平县| 延津县| 桐梓县| 达拉特旗| 广德县| 仙桃市| 通城县| 大荔县| 宣威市| 英超| 青海省| 民丰县| 漾濞| 施秉县| 庆云县| 获嘉县| 温州市| 循化| 明水县| 廊坊市| 射洪县| 津市市| 南汇区| 昌宁县| 客服| 沂水县| 托克逊县| 凤山县| 宜兰市| 溧阳市| 鹿邑县| 桑日县|