jQuery實現(xiàn)中獎播報功能(讓文本滾動起來) 簡單設置數(shù)值即可
在很多場景中,我們需要使用到中獎信息播報,或者一些文本信息循環(huán)滾動播報,在結合實際的開發(fā)中,然后也百度查詢了相關的知識點,現(xiàn)在送上jQuery實現(xiàn)文本滾動。
1:html代碼文件
相關使用說明也在頁面相關位置標注啦
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>文本滾動</title>
<link rel="stylesheet" type="text/css" href="css/style.css" rel="external nofollow" >
<script src="jquery-1.9.1.min.js"></script>
<script src="jquery.scroll.js"></script>
<script src="txtscroll.js"></script>
<style>
.new_trade .new_trade_body .yl{margin-top:4px}
.fix_tradebottom{clear:both;background:#222; position:fixed;width:100%;left:0;z-index:12;bottom:0}
.trade_win{height:26px;line-height:26px;width:54%;text-align:center;color:#646464;font-size:12px;border-top: 1px solid #c8c8c8;border-bottom: 1px solid #c8c8c8;background:#f3f3f3;}
#trade_win{height:26px;line-height:26px;width:100%;overflow:hidden;}
.trade_win ul{height:26px;line-height:26px}
.trade_win li{width:100%;display:block;}
.trade_win li span{ no-repeat;background-position: 0px 3px;background-size:13px 10px; padding-left:18px;}
</style>
</head>
<h2 style="margin-left: 426px;">縱向滾動</h2>
<div class="trade_win" style="margin-left: 426px;">
<div id="trade_win">
<ul>
<li><span>恭喜道1中獎 825.00元</span></li>
<li><span>恭喜道2中獎 825.00元</span></li>
<li><span>恭喜道3中獎 825.00元</span></li>
<li><span>恭喜道4中獎 825.00元</span></li>
<li><span>恭喜道5中獎 825.00元</span></li>
<li><span>恭喜道6中獎 825.00元</span></li>
<li><span>恭喜道7中獎 825.00元</span></li>
</ul>
</div>
</div>
<script>
$(document).ready(function(){
//speed:滾動的速度 數(shù)值越大速度越慢。 timer:數(shù)據(jù)停留時間 數(shù)值越大停留時間越久
$('#trade_win').Scroll({ line: 1, speed: 1000, timer: 1500 });
})
</script>
<div class="demo">
<h2>橫向滾動</h2>
<div class="demolist">
<ul class="ul">
<li>
<h4>示例1 - 無滾動效果</h4>
<div class="demo-cont">
<div class="txt-scroll txt-scroll-default">
<div class="scrollbox">
<div class="txt">
微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下
</div>
</div>
</div>
</div>
<div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 50 });
//說明:文本長度不夠無滾動效果
</pre>
</div>
</li>
<li>
<h4>示例2 - 默認參數(shù)配置</h4>
<div class="demo-cont">
<div class="txt-scroll txt-scroll-default">
<div class="scrollbox">
<div class="txt">
微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下
</div>
</div>
</div>
</div>
<div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 50 });
</pre>
</div>
</li>
<li>
<h4>示例2 - 自定義參數(shù)配置</h4>
<div class="demo-cont">
<div class="txt-scroll txt-scroll-curs">
<div class="scrollbox">
<div class="txt">
微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關于一篇文章生成一張海報圖片,用于用戶保存之后分享,實際開發(fā)的過程中遇到的一些問題如下
</div>
</div>
</div>
</div>
<div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 20 });
</pre>
</div>
</li>
</ul>
</div>
</div>
<script>
//默認案例
window.onload = function () {
$('.txt-scroll-default').txtscroll({
'speed': 50
});
};
//自定義參數(shù)案例
$('.txt-scroll-curs').txtscroll({
'speed': 10
});
</script>
</body>
</html>
2:關鍵的JS 文件
(function($){
$.fn.extend({
Scroll:function(opt,callback){
if(!opt) var opt={};
var _btnUp = $("#"+ opt.up);
var _btnDown = $("#"+ opt.down);
var timerID;
var _this=this.eq(0).find("ul:first");
var lineH=_this.find("li:first").height(), //獲取行高
line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滾動的行數(shù),默認為一屏,即父容器高度
auto=opt.auto!=null?opt.auto:true,//是否自動滾動,默認自動
cycle=opt.cycle!=null?opt.cycle:true,//是否循環(huán)滾動,默認循環(huán)
speed=opt.speed!=null?parseInt(opt.speed,10):500; //卷動速度,數(shù)值越大,速度越慢(毫秒)
timer=opt.timer!=null?opt.timer:3000; //滾動的時間間隔(毫秒)
if(line==0) line=1;
var upHeight=0-line*lineH;
var liCount=_this.find("li").length;//LI的總數(shù)
var showCount=parseInt(this.height()/lineH);//顯示出來的LI數(shù)量
var currentCount=showCount;
var scrollUp=function(){
if(!cycle && currentCount>=liCount) return;
_btnUp.unbind("click",scrollUp);
_this.animate({
marginTop:upHeight
},speed,function(){
for(i=1;i<=line;i++){
if(!cycle && currentCount>=liCount) break;
currentCount++;
_this.find("li:first").appendTo(_this);
}
_this.css({marginTop:0});
_btnUp.bind("click",scrollUp);
});
}
var scrollDown=function(){
if(!cycle && currentCount<=showCount) return;
_btnDown.unbind("click",scrollDown);
for(i=1;i<=line;i++){
if(!cycle && currentCount<=showCount) break;
currentCount--;
_this.find("li:last").show().prependTo(_this);
}
_this.css({marginTop:upHeight});
_this.animate({
marginTop:0
},speed,function(){
_btnDown.bind("click",scrollDown);
});
}
var autoPlay = function(){
if(auto) {
if(timer>0) timerID = window.setInterval(scrollUp,timer);
}
};
var autoStop = function(){
if(timer)window.clearInterval(timerID);
};
_this.hover(autoStop,autoPlay).mouseout();
_btnUp.css("cursor","pointer").click( scrollUp ).hover(autoStop,autoPlay);
_btnDown.css("cursor","pointer").click( scrollDown ).hover(autoStop,autoPlay);
}
})
})(jQuery);

總結
到此這篇關于jQuery實現(xiàn)中獎播報(讓文本滾動起來) 簡單設置數(shù)值即可的文章就介紹到這了,更多相關jquery 中獎播報 滾動內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
jquery easyui combobox模糊過濾(示例代碼)
這篇文章主要介紹了jquery easyui combobox模糊過濾(示例代碼)。需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11
JQuery頁面隨滾動條動態(tài)加載效果的簡單實現(xiàn)(推薦)
下面小編就為大家?guī)硪黄狫Query頁面隨滾動條動態(tài)加載效果的簡單實現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
淺談jQuery中Ajax事件beforesend及各參數(shù)含義
下面小編就為大家?guī)硪黄獪\談jQuery中Ajax事件beforesend及各參數(shù)含義。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,祝大家游戲愉快哦2016-12-12
jquery插件之信息彈出框showInfoDialog(成功/錯誤/警告/通知/背景遮罩)
某某同學最近寫了個基于jquery的信息彈出插件showInfoDialog,該插件對背景進行遮罩,然后彈出信息顯示框,信息顯示種類包括(操作成功/錯誤信息/警告信息/通知信息)感興趣的朋友可以了解下2013-01-01

