您好,登錄后才能下訂單哦!
特效描述:利用jQuery實(shí)現(xiàn) 輸入文字 彈幕顯示 動(dòng)畫特效,利用jQuery實(shí)現(xiàn)輸入文字彈幕顯示動(dòng)畫特效
代碼結(jié)構(gòu)
<script src="js/jquery-3.0.0.min.js"></script>
<div class="barrager">
<div><span>我的女神</span></div>
<div><span>溫婉而雅</span></div>
<div><span>溫柔美麗</span></div>
<div><span>溫柔美麗</span></div>
<div><span>溫柔美麗</span></div>
<div><span>我最愛(ài)的葉老師</span></div>
<div><span>氣質(zhì)型</span></div>
<div><span>風(fēng)趣幽默</span></div>
<div><span>風(fēng)趣幽默</span></div>
</div>
<div class="addBarrager clearfix">
<input type="text" maxlength="10" autocomplete="off" class="fl barVal" placeholder="描述你對(duì)TA的印象 限10個(gè)字">
<button class="submit fr">發(fā)布</button>
</div>
<script type="text/javascript">
$(function () {
$(".barrager").barrager()
});
(function () {
var Barrager = function (ele,options) {
var defaults = {
color:["#ff9999","#35d2f4","#9ee353","#9d77ff","#4785d9","#ff9333","#5bdea8","#51befc"],
wrap:ele
};
this.settings = $.extend({},defaults,options||{});
this._init();
this.bindEven();
};
Barrager.prototype = {
_init:function () {
var item = $(this.settings.wrap).find("div");
for(var i = 0;i<item.length;i++){
item.eq(i).css({
top:this.getReandomTop()+"px",
color:this.getReandomColor(),
fontSize:this.getReandomSize()+"px"
});
item.eq(i).css({
right:-item.eq(i).width()
})
}
this.randomTime(0);
},
bindEven:function () {
var _this = this;
$(".addBarrager .submit").on('click',function () {
_this._click(_this);
});
},
getReandomColor:function () {
var max = this.settings.color.length;
var randomNum = Math.floor(Math.random()max);
return this.settings.color[randomNum];
},
getReandomTop:function () {
var top = (Math.random()450).toFixed(1);
return top;
},
getReandomSize:function () {
var size = (12+Math.random()28);
return size;
},
getReandomTime:function () {
var time = Math.floor((8+Math.random()10));
return time*1000;
},
randomTime:function (n) {
var obj = $(this.settings.wrap).find("div");
var _this = this;
var len = obj.length;
if(n>=len){
n=0;
}
setTimeout(function () {
n++;
_this.randomTime(n)
},1000);
var item = obj.eq(n),_w = item.outerWidth(!0);
item.animate({
left:-_w
},_this.getReandomTime(),"linear",function () {
item.css({right:-_w,left:""});
_this.randomTime(n)
});
},
_click:function (obj) {
var _this = obj;
var _val = $(".barVal");
if(_val.val() == ""){
alert("請(qǐng)描述你對(duì)TA的印象!");
return false;
}
$(_this.settings.wrap).append("<div><span class='new'>"+_val.val()+"</span></div>");
_this._init();
_val.val("");
}
};
$.fn.barrager = function (opt) {
var bger = new Barrager(this,opt);
}
})(jQuery);
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。