基于jquery實現(xiàn)彈幕效果
更新時間:2016年09月29日 14:12:16 作者:一直在路上前行
這篇文章主要為大家詳細(xì)介紹了基于jquery實現(xiàn)彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
用jquery寫的一個彈幕,供大家參考,具體內(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;">開始彈幕</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(" ");
});
});
//隨機獲取顏色值
function getReandomColor() {
return '#' + (function(h) {
return new Array(7 - h.length).join("0") + h
})((Math.random() * 0x1000000 << 0).toString(16))
}
//生成隨機數(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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實現(xiàn)平滑滾動的標(biāo)簽分欄切換效果
這篇文章主要介紹了jQuery實現(xiàn)平滑滾動的標(biāo)簽分欄切換效果,涉及jquery鼠標(biāo)事件及頁面元素樣式的動態(tài)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
jquery調(diào)用asp.net 頁面后臺的實現(xiàn)代碼
前一篇介紹jquery調(diào)用webservice,這一篇引用的是用jquery直接調(diào)用aspx后臺方法。2011-04-04
jquery通過a標(biāo)簽刪除table中的一行的代碼
刪除table中的一行的方法有很多,在本文為大家介紹下jquery是如何做到的,下面有個不錯的示例,喜歡的朋友可以參考下2013-12-12
jquery 實現(xiàn)兩級導(dǎo)航菜單附效果圖
兩級導(dǎo)航菜單在網(wǎng)頁中非常實用,實現(xiàn)的方法也有很多,本文為大家介紹下使用jquery是如何實現(xiàn)的2014-03-03
BootStrap中jQuery插件Carousel實現(xiàn)輪播廣告效果
輪播廣告在網(wǎng)站中的應(yīng)用實在是太常見了,下面說一說怎樣使用bootstrap中的Carousel插件來實現(xiàn)輪播廣告效果,感興趣的朋友一起看看吧2017-03-03

