基于jquery實(shí)現(xiàn)彈幕效果
用jquery寫(xiě)的一個(gè)彈幕,供大家參考,具體內(nèi)容如下
效果圖:

源碼:
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="favicon.ico" rel="Bookmark" type="image/x-icon" />
-->
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>JQuery彈幕</title>
<link href="" rel="stylesheet" />
</script>
<style type="text/css">
body {
overflow: hidden;
}
.content {
overflow: hidden;
}
.ctxt {
background: burlywood;
width: 100%;
overflow: hidden;
margin: 0 auto;
z-index: 9999;
}
.ctxt p {
left: 95%;
margin: 0;
padding: 0;
z-index: 99;
overflow: hidden;
}
#msg{
height: 24px;
width: 200px;
}
#barrage {
color: gainsboro;
border: 1px solid aqua;
font-size: 12px;
border-radius: 10px;
float: right;
}
#style {
margin-top: 10px;
}
#publish {
display: none;
}
video {
width: 100%;
overflow: hidden;
z-index: -99999;
}
#danmu {
position: absolute;
overflow: hidden;
font-size:20px;
}
</style>
</head>
<body>
<div class="content">
<div id="" class="ctxt">
<video id="vodio" autoplay="autoplay">
<source src="video/1429411761ed3dc100c73251.mp4" type="video/mp4">
</source>
</video>
</div>
<div id="style">
<button id="barrage"> <font style="color: white;">開(kāi)始彈幕</font></button>
<div id="publish">
<form method="post" align="center">
<input type="text" id="msg" />
<button type="button" id="submitBut">發(fā)布</button>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-2.1.1.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$("#barrage").click(function() {
$("#publish").toggle();
});
$("#submitBut").click(function() {
var msgtxt = $("#msg").val();
var colortxt = getReandomColor();
var topPos = generateMixed(3);
if(topPos > 500) {
topPos = 30;
}
var newtxt = '<p id="danmu" style="top:' + topPos + 'px; color:' + colortxt + '">' + $("#msg").val() + '</p>';
$(".ctxt").prepend(newtxt);
var addTextW = $(".ctxt").find("p").width();
$(".ctxt p").animate({
left: '-' + addTextW + 20 + "px"
}, 30000, function() {
$(this).hide();
});
$("#msg").val(" ");
});
});
//隨機(jī)獲取顏色值
function getReandomColor() {
return '#' + (function(h) {
return new Array(7 - h.length).join("0") + h
})((Math.random() * 0x1000000 << 0).toString(16))
}
//生成隨機(jī)數(shù)據(jù)。n表示位數(shù)
var jschars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
function generateMixed(n) {
var res = "";
for(var i = 0; i < n; i++) {
var id = Math.ceil(Math.random() * 9);
res += jschars[id];
}
return res;
}
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js實(shí)現(xiàn)七夕表白彈幕效果 jQuery實(shí)現(xiàn)彈幕技術(shù)
- jQuery實(shí)現(xiàn)簡(jiǎn)單彈幕制作
- jQuery實(shí)現(xiàn)彈幕特效
- jquery實(shí)現(xiàn)直播彈幕效果
- jQuery實(shí)現(xiàn)簡(jiǎn)單彈幕效果
- 簡(jiǎn)單實(shí)現(xiàn)jQuery彈幕效果
- 基于jQuery實(shí)現(xiàn)彈幕APP
- 又一枚精彩的彈幕效果jQuery實(shí)現(xiàn)
- 終于實(shí)現(xiàn)了!精彩的jquery彈幕效果
- jQuery實(shí)現(xiàn)彈幕效果案例
相關(guān)文章
基于jQuery實(shí)現(xiàn)的設(shè)置文本區(qū)域的光標(biāo)位置
之前做一個(gè)代碼提示的功能涉及到在文本框中插入文本的操作,需要獲得當(dāng)前光標(biāo)位置插入文本,本文章向大家介紹jQuery如何設(shè)置文本區(qū)域的光標(biāo)位置,需要的朋友可以參考一下2018-06-06
jQuery實(shí)現(xiàn)基本淡入淡出效果的方法詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)基本淡入淡出效果的方法,結(jié)合實(shí)例形式詳細(xì)分析了jQuery使用fadeIn()、fadeOut()及fadeToggle()等方法控制頁(yè)面元素淡入淡出顯示效果的相關(guān)操作技巧,需要的朋友可以參考下2018-09-09
jQuery 獲取跨域XML(RSS)數(shù)據(jù)的相關(guān)總結(jié)分析
下面小編就為大家?guī)?lái)一篇jQuery 獲取跨域XML(RSS)數(shù)據(jù)的相關(guān)總結(jié)分析。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
JQuery拖動(dòng)表頭邊框線調(diào)整表格列寬效果代碼
當(dāng)鼠標(biāo)停留在表頭邊框線上,接著拖動(dòng)鼠標(biāo),會(huì)在表格中出現(xiàn)一條隨鼠標(biāo)移動(dòng)的豎線,最后放開(kāi)鼠標(biāo),表格列寬會(huì)被調(diào)整2014-09-09
jQuery實(shí)現(xiàn)輸入框下拉列表樹(shù)插件特效代碼分享
這篇文章主要介紹了jQuery實(shí)現(xiàn)輸入框下拉列表樹(shù)特效,推薦給大家,有需要的小伙伴可以參考下。2015-08-08
基于JQuery的簡(jiǎn)單實(shí)現(xiàn)折疊菜單代碼
利用JQUERY簡(jiǎn)單的實(shí)現(xiàn)功能菜單的折疊效果。本人初學(xué),寫(xiě)后臺(tái)稍多一點(diǎn),很少寫(xiě)前臺(tái)的效果。還請(qǐng)大蝦們多多指教。2010-09-09
jQuery實(shí)現(xiàn)圖片加載完成后改變圖片大小的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)圖片加載完成后改變圖片大小的方法,結(jié)合實(shí)例形式分析了jQuery圖片樣式與頁(yè)面元素屬性動(dòng)態(tài)操作的相關(guān)技巧,需要的朋友可以參考下2016-03-03
jQuery動(dòng)態(tài)添加的元素綁定事件處理函數(shù)代碼
有一段時(shí)間沒(méi)用jquery了,今天又碰到這個(gè)問(wèn)題。當(dāng)時(shí)是知道有l(wèi)ivejquery可以解決。但是我并不喜歡為了這個(gè)而另外加載一個(gè)。2011-08-08
一個(gè)可綁定數(shù)據(jù)源的jQuery數(shù)據(jù)表格插件
此文將實(shí)現(xiàn)一個(gè)的jQuery表格插件jQuery.DataGrid。需要的朋友可以參考下。2010-07-07

