jQuery實現(xiàn)的彈幕效果完整實例
本文實例講述了jQuery實現(xiàn)的彈幕效果。分享給大家供大家參考,具體如下:
看視頻的時候老是會出現(xiàn)一些彈幕,對于這個看著很高大上的特效,其實也不難實現(xiàn)。
先來看看運行效果:

下面將整個代碼顯示出來:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>www.dhdzp.com彈幕</title>
<style type="text/css">
html,body{
background:#efefef;
height:100%;
}
.danmu{
width: 100px;
height:30px;
line-height: 28px;
background: green;
border-radius: 5px;
border:1px solid #fff;
color: #fff;
outline: none;
}
div.mask{
position:fixed;
width:100%;
height:100%;
background:rgba(0,0,0,0.8);
opacity:0.5;
top:0px;
left:0px;
}
div.bottom{
width:100%;
height:77px;
background:linear-gradient(#ccc,#4a4a4a);
position:fixed;
bottom:0px;
left:0px;
text-align:center;
line-height:77px;
}
div.bottom input.content{
width:50%;
min-width: 200px;
height:37px;
border:none;
border-radius:10px 0px 0px 10px;
font-size:16px;
padding:0 10px;
outline:none;
}
div.bottom a.send{
background-color:green;
color:#fff;
display:inline-block;
width:100px;
height:38px;
line-height:37px;
text-align:center;
position:relative;
left:-10px;
top:2px;
border-radius:0px 10px 10px 0px;
text-decoration:none;
font-family:'Microsoft Yahei';
}
div.mask a.button{
width:30px;
height:30px;
border-radius:50%;
background-color:green;
color:#fff;
position:fixed;
top:20px;
right:20px;
text-align:center;
line-height:30px;
font-size:20px;
font-family:'Microsoft Yahei';
border:1px solid #fff;
text-decoration:none;
cursor:pointer;
}
div.text{
color:#fff;
position:fixed;
right:0px;
font-size:20px;
white-space: nowrap;
}
</style>
</head>
<body>
<button class="danmu">彈幕技術(shù)</button>
<div class="mask">
<a href="#" rel="external nofollow" rel="external nofollow" class="button">X</a>
</div>
<!-- 底部發(fā)言框前端 -->
<div class="bottom">
<input class="content"></input>
<a href="#" rel="external nofollow" rel="external nofollow" class="send">發(fā)表言論</a>
</div>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$("a.send").click(function(){
var val=$(".content").val();
var content=$("<div class='text'>"+val+"</div>");
var top=Math.random()*$(document.body).height()+40+"px";
content.css("top",top);
$(".mask").append(content);
content.animate({right:$(document.body).width()+100},8000,function(){
$(this).remove();
})
});
$('.button').click(function(){
$('div.mask').fadeOut(500);
});
$(".danmu").click(function(){
$('div.mask').fadeIn(500);
});
</script>
</body>
</html>
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
jQuery序列化form表單數(shù)據(jù)為JSON對象的實現(xiàn)方法
這篇文章主要介紹了jQuery序列化form表單數(shù)據(jù)為JSON對象的實現(xiàn)方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09
js獲取通過ajax返回的map型的JSONArray的方法
下面是js獲取通過ajax返回的map型的JSONArray的詳細代碼,需要的朋友可以參考下2014-01-01
IE下使用jQuery重置iframe地址時內(nèi)存泄露問題解決辦法
這篇文章主要介紹了IE下使用jQuery重置iframe地址時內(nèi)存泄露問題解決辦法,需要的朋友可以參考下2015-02-02
jQuery實現(xiàn)選中彈出窗口選擇框內(nèi)容后賦值給文本框的方法
這篇文章主要介紹了jQuery實現(xiàn)選中彈出窗口選擇框內(nèi)容后賦值給文本框的方法,涉及jQuery響應(yīng)鼠標(biāo)事件動態(tài)操作頁面元素屬性的相關(guān)技巧,需要的朋友可以參考下2015-11-11
jquery+html5時鐘特效代碼分享(可設(shè)置鬧鐘并且語音提醒)
這篇文章主要為大家詳細介紹了Jquery+html5可設(shè)置鬧鐘并且會語音提醒的時鐘特效,功能實現(xiàn)非常簡單,推薦給大家,有需要的小伙伴可以參考下2015-08-08

