jQuery實(shí)現(xiàn)彈幕特效
案例簡(jiǎn)介
jQuery實(shí)現(xiàn)彈幕效果,代碼如下。
案例目錄

HTML部分
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery彈幕案例</title>
<link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" />
</head>
<body>
<div class="box">
<div class="top"></div>
<div class="bot">
<input type="text" id="txt" placeholder="我來說兩句。。。" />
<button type="button" id="btn">發(fā)送</button>
</div>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
$(function() {
var colors = ["red", "green", "hotpink", "pink", "cyan", "yellowgreen", "purple", "deepskyblue"];
$("#btn").on("click", function() {
var randomColor = parseInt(Math.random() * colors.length);
var randomY = parseInt(Math.random() * 400);
$("<span></span>") //創(chuàng)建span
.text($("#txt").val()) //設(shè)置內(nèi)容
.css("color", colors[randomColor]) //設(shè)置字體顏色
.css("left", "1400px") //設(shè)置left值
.css("top", randomY) //設(shè)置top值
.animate({
left: -500
}, 10000, "linear", function() {
//到了終點(diǎn),需要?jiǎng)h除
$(this).remove();
}) //添加動(dòng)畫
.appendTo(".top");
$("#txt").val("");
});
});
</script>
</body>
</html>
CSS部分
* {
margin: 0;
padding: 0;
}
.box {
width: 1600px;
height: 757px;
}
.top {
width: 100%;
height: 660px;
position: relative;
}
.bot {
width: 100%;
height: 97px;
background-color: #666666;
position: relative;
}
#txt {
width: 300px;
height: 30px;
border-radius: 5px;
position: absolute;
left: 50%;
margin-left: -150px;
top: 50%;
margin-top: -15px;
border: none;
}
#btn {
width: 60px;
height: 30px;
color: white;
background-color: red;
position: absolute;
left: 955px;
top: 34px;
border: none;
}
span {
position: absolute;
color: #000;
font-size: 50px;
line-height: 1.5em;
cursor: pointer;
white-space: nowrap;
}
效果展示

以上就是jQuery實(shí)現(xiàn)彈幕效果的代碼,希望對(duì)您有幫助!
源碼下載:jQuery彈幕
以上就是本文的全部?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)簡(jiǎn)單彈幕效果
- 簡(jiǎn)單實(shí)現(xiàn)jQuery彈幕效果
- 基于jQuery實(shí)現(xiàn)彈幕APP
- 基于jquery實(shí)現(xiàn)彈幕效果
- 又一枚精彩的彈幕效果jQuery實(shí)現(xiàn)
- 終于實(shí)現(xiàn)了!精彩的jquery彈幕效果
- jQuery實(shí)現(xiàn)彈幕效果案例
相關(guān)文章
JQuery的Ajax跨域請(qǐng)求原理概述及實(shí)例
ajax跨域請(qǐng)求的問題,JQuery對(duì)于Ajax的跨域請(qǐng)求有兩類解決方案,不過都是只支持get方式,接下來為大家詳細(xì)介紹下客戶端JQuery.ajax的調(diào)用代碼2013-04-04
jQuery的三種bind/One/Live/On事件綁定使用方法
jQuery是 一款優(yōu)秀的JavaScript框架,在舊版里主要用bind()方法,在新版里又多了兩種One(),Live(),下面介紹這幾種方法的使用2017-02-02
jQuery實(shí)現(xiàn)區(qū)域打印功能代碼詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)區(qū)域打印功能代碼詳解的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
jquery實(shí)現(xiàn)異步文件上傳ajaxfileupload.js
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)異步文件上傳ajaxfileupload.js,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10
Jquery中LigerUi的彈出編輯框(實(shí)現(xiàn)方法)
本篇文章是對(duì)Jquery中LigerUi的彈出編輯框的實(shí)現(xiàn)方法進(jìn)行了分析介紹,需要的朋友可以參考下2013-07-07
jQuery實(shí)現(xiàn)手勢(shì)解鎖密碼特效
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)手勢(shì)解鎖密碼特效,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
jquery中的$(document).ready()使用小結(jié)
本篇文章主要是對(duì)jquery中的$(document).ready()使用方法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02

