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

javascript實現(xiàn)視頻彈幕效果(兩個版本)

 更新時間:2021年09月10日 15:22:49   作者:Maybion  
這篇文章主要為大家詳細介紹了javascript實現(xiàn)視頻彈幕效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了javascript實現(xiàn)視頻彈幕效果的具體代碼,供大家參考,具體內(nèi)容如下

基礎版本

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="utf-8">
 <style>
 * {
 margin: 0;
 padding: 0;
 }

 .dm {
 width: 800px;
 height: 600px;
 background-color: blue;
 margin: 0 auto;
 }

 .box {
 height: 500px;
 background-color: #000;
 position: relative;
 overflow: hidden;
 }

 video {
 width: 100%;
 height: 100%;
 }

 .info {
 text-align: center;
 margin-top: 20px;
 }

 input[type=text] {
 width: 500px;
 height: 50px;
 }

 input[type=button] {
 height: 50px;
 width: 100px;

 }

 span {
 position: absolute;
 /* 文本強制不換行 */
 white-space: nowrap;
 font: bold 18px '微軟雅黑';
 }
 </style>

</head>

<body>
 <div class="dm">
 <div class="box">
 <video src="m.mp4" controls></video>
 </div>
 <div class="info">
 <input type="text" maxlength="30" id="txt">
 <input type="button" value="發(fā)射" id="emit">
 </div>
 </div>
 <script src="jquery-1.12.4.js"></script>
 <script>
 // 0. 用一個數(shù)組保存一組顏色值
 var colors = ['red', 'green', 'yellow', '#fff', 'pink', 'blue'];
 // 1. 給發(fā)射按鈕注冊點擊事件
 $('#emit').click(function () {
 // 2. 獲取文本框的內(nèi)容
 var v = $('#txt').val();
 // 3. 創(chuàng)建span標簽,并設置內(nèi)容,設置樣式,最后追加到類名為box的div中
 var $span = $('<span></span>');
 $span.text(v)
 .css({
  left: $('.box').width(),
  top: parseInt(Math.random() * $('.box').height()),
  color: colors[parseInt(Math.random() * colors.length)]
 }).appendTo('.box');
 // 4. 讓當前的span產(chǎn)生動畫 left 為-span的寬度
 $span.animate({
 left: -1 * $span.width()
 }, 6000, 'linear', function () {
 // 當動畫結(jié)束后,刪除該元素
 $span.remove();
 })
 });
 </script>

</body>

</html>

加強版本

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="utf-8">
 <style>
 * {
 margin: 0;
 padding: 0;
 }

 .dm {
 width: 800px;
 height: 600px;
 background-color: blue;
 margin: 0 auto;
 }

 .box {
 height: 500px;
 background-color: #000;
 position: relative;
 overflow: hidden;
 }

 video {
 width: 100%;
 height: 100%;
 }

 .info {
 text-align: center;
 margin-top: 20px;
 }

 input[type=text] {
 width: 500px;
 height: 50px;
 }

 input[type=button] {
 height: 50px;
 width: 100px;

 }

 span {
 position: absolute;
 /* 文本強制不換行 */
 white-space: nowrap;
 font: bold 18px '微軟雅黑';
 }
 </style>

</head>

<body>
 <div class="dm">
 <div class="box">
 <!-- controls 如果出現(xiàn)該屬性,則向用戶顯示控件,比如播放按鈕。 -->
 <video src="m.mp4" controls></video>
 </div>
 <div class="info">
 <input type="radio" value="" id="ban" name="1">精簡</input>
 <input type="radio" value="" id="vip" name="1">VIP尊享</input>
 <input type="text" maxlength="30" id="txt">
 <input type="button" value="發(fā)射" id="emit">
 </div>
 </div>
 <script src="jquery-1.12.4.js"></script>
 <script>
 // 0. 用一個數(shù)組保存一組顏色值
 var colors = ['red', 'green', 'yellow', '#fff', 'pink', 'blue'];

 //定義一個變量,定義其他樣式的
 b = 0
 $('#ban').click(function () {
 b = 1;
 });
 $('#vip').click(function () {
 b = 2;
 });




 // 1. 給發(fā)射按鈕注冊點擊事件
 $('#emit').click(function () {
 // 2. 獲取文本框的內(nèi)容
 var v = $('#txt').val();
 // 3. 創(chuàng)建span標簽,并設置內(nèi)容,設置樣式,最后追加到類名為box的div中
 var $span = $('<span></span>');

 //定義CSS樣式,讓它是一個數(shù)組形式表現(xiàn)
 css = [{
  "left": $('.box').width(),
  "top": parseInt(Math.random() * $('.box').height()),
  "color": colors[parseInt(Math.random() * colors.length)]
 },
 {
  "left": $('.box').width(),
  "top": parseInt(Math.random() * ($('.box').height() / 2)),
  "color": colors[parseInt(Math.random() * colors.length)]
 },
 {
  "left": $('.box').width(),
  "top": parseInt(Math.random() * $('.box').height()),
  "color": "yellow",
  "fontSize": 50,
  "fontFamily": "楷體"
 }
 ]
 //看看能不能打印出數(shù)組中的東西
 // console.log(abc[1])

 $span.text(v)
 .css(css[b])
 .appendTo('.box');

 // 4. 讓當前的span產(chǎn)生動畫 left 為-span的寬度

 //打印出文本長度
 // console.log(v.length)

 $span.animate({
  left: -1 * $span.width()
 }, (30 - v.length) * 333, 'linear',
 function () {
  // 當動畫結(jié)束后,刪除該元素
  $span.remove();
 })
 });
 </script>

</body>

</html>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • div浮層,滾動條移動,位置保持不變的4種方法匯總

    div浮層,滾動條移動,位置保持不變的4種方法匯總

    這篇文章主要是對div浮層,滾動條移動,位置保持不變的4種方法進行了匯總介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2013-12-12
  • js獲取指定日期周數(shù)以及星期幾的小例子

    js獲取指定日期周數(shù)以及星期幾的小例子

    根據(jù)某年某周獲取一周的日期。如開始日期規(guī)定為星期四到下一周的星期五為一周,需要的朋友可以參考下
    2014-06-06
  • JavaScript利用canvas實現(xiàn)星空效果

    JavaScript利用canvas實現(xiàn)星空效果

    Canvas對于我們前端來說是一個非常強大的工具,它可以實現(xiàn)各種復雜的圖形和動畫效果,我們?nèi)绻軌蚴炀氄莆账?我們就可以做很多炫酷的效果,本文就給大家介紹了用canvas畫出一片星空的方法,需要的朋友可以參考下
    2023-11-11
  • 掃微信小程序碼實現(xiàn)網(wǎng)站登陸實現(xiàn)解析

    掃微信小程序碼實現(xiàn)網(wǎng)站登陸實現(xiàn)解析

    這篇文章主要介紹了掃微信小程序碼實現(xiàn)網(wǎng)站登陸實現(xiàn)解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-08-08
  • JavaScript之Array常見的方法詳解

    JavaScript之Array常見的方法詳解

    這篇文章主要為大家介紹了JavaScript之Array常見的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助V
    2021-11-11
  • 理解javascript中的嚴格模式

    理解javascript中的嚴格模式

    這篇文章主要幫助大家理解javascript中的嚴格模式,何為嚴格模式,如何啟用嚴格模式,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Javascript實現(xiàn)秒表倒計時功能

    Javascript實現(xiàn)秒表倒計時功能

    這篇文章主要為大家詳細介紹了Javascript實現(xiàn)秒表倒計時功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • 用JavaScript調(diào)用WebService的示例

    用JavaScript調(diào)用WebService的示例

    JavaScript用htc實現(xiàn)WebService的調(diào)用
    2008-04-04
  • uni-app開發(fā)案例之video視頻組件

    uni-app開發(fā)案例之video視頻組件

    最近uni-app使用video組件碰到的一系列問題,所以下面這篇文章主要給大家介紹了關(guān)于uni-app開發(fā)案例之video視頻組件的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-09-09
  • JavaScript解析URL參數(shù)示例代碼

    JavaScript解析URL參數(shù)示例代碼

    通過js解析URL參數(shù),本文創(chuàng)建了一個js類,并引用Request.QueryString,感興趣的朋友可以參考下,希望對大家有所幫助
    2013-08-08

最新評論