溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

jQuery如何實(shí)現(xiàn)中獎(jiǎng)播報(bào)功能

發(fā)布時(shí)間:2021-05-10 12:51:44 來(lái)源:億速云 閱讀:190 作者:小新 欄目:web開發(fā)

這篇文章主要介紹jQuery如何實(shí)現(xiàn)中獎(jiǎng)播報(bào)功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

jquery是什么

jquery是一個(gè)簡(jiǎn)潔而快速的JavaScript庫(kù),它具有獨(dú)特的鏈?zhǔn)秸Z(yǔ)法和短小清晰的多功能接口、高效靈活的css選擇器,并且可對(duì)CSS選擇器進(jìn)行擴(kuò)展、擁有便捷的插件擴(kuò)展機(jī)制和豐富的插件,是繼Prototype之后又一個(gè)優(yōu)秀的JavaScript代碼庫(kù),能夠用于簡(jiǎn)化事件處理、HTML文檔遍歷、Ajax交互和動(dòng)畫,以便快速開發(fā)網(wǎng)站。

1:html代碼文件

     相關(guān)使用說明也在頁(yè)面相關(guān)位置標(biāo)注啦

<!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>文本滾動(dòng)</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>
<h3 >縱向滾動(dòng)</h3>
<div class="trade_win" >
 <div id="trade_win">
 <ul>
 <li><span>恭喜道1中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道2中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道3中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道4中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道5中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道6中獎(jiǎng) 825.00元</span></li>
 <li><span>恭喜道7中獎(jiǎng) 825.00元</span></li>
 </ul>
 </div>
 </div>
<script>
 $(document).ready(function(){
 //speed:滾動(dòng)的速度 數(shù)值越大速度越慢。 timer:數(shù)據(jù)停留時(shí)間 數(shù)值越大停留時(shí)間越久
 $('#trade_win').Scroll({ line: 1, speed: 1000, timer: 1500 });
 })
</script>
<div class="demo">
 
<h3>橫向滾動(dòng)</h3>
 <div class="demolist">
 <ul class="ul">
 <li>
 <h5>示例1 - 無(wú)滾動(dòng)效果</h5>
 <div class="demo-cont">
 <div class="txt-scroll txt-scroll-default">
  <div class="scrollbox">
  <div class="txt">
   微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下
  </div>
  </div>
 </div>
 </div>
 <div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 50 });
//說明:文本長(zhǎng)度不夠無(wú)滾動(dòng)效果
</pre>
 </div>
 </li>
 <li>
 <h5>示例2 - 默認(rèn)參數(shù)配置</h5>
 <div class="demo-cont">
 <div class="txt-scroll txt-scroll-default">
  <div class="scrollbox">
  <div class="txt">
   微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下
  </div>
  </div>
 </div>
 </div>
 <div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 50 });
</pre>
 </div>
 </li>
 <li>
 <h5>示例2 - 自定義參數(shù)配置</h5>
 <div class="demo-cont">
 <div class="txt-scroll txt-scroll-curs">
  <div class="scrollbox">
  <div class="txt">
   微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下.微信小程序端有關(guān)于一篇文章生成一張海報(bào)圖片,用于用戶保存之后分享,實(shí)際開發(fā)的過程中遇到的一些問題如下
  </div>
  </div>
 </div>
 </div>
 <div class="jsset">
<pre>
$('.txt-scroll').txtscroll({ 'speed': 20 });
</pre>
 </div>
 </li>
 </ul>
 </div>
 </div>
 <script>
 //默認(rèn)案例
 window.onload = function () {
 $('.txt-scroll-default').txtscroll({
 'speed': 50
 });
 };
 //自定義參數(shù)案例
 $('.txt-scroll-curs').txtscroll({
 'speed': 10
 });
 </script>
</body>
</html>

2:關(guān)鍵的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), //每次滾動(dòng)的行數(shù),默認(rèn)為一屏,即父容器高度
   auto=opt.auto!=null?opt.auto:true,//是否自動(dòng)滾動(dòng),默認(rèn)自動(dòng)
   cycle=opt.cycle!=null?opt.cycle:true,//是否循環(huán)滾動(dòng),默認(rèn)循環(huán)
   speed=opt.speed!=null?parseInt(opt.speed,10):500; //卷動(dòng)速度,數(shù)值越大,速度越慢(毫秒)
   timer=opt.timer!=null?opt.timer:3000; //滾動(dòng)的時(shí)間間隔(毫秒)
  if(line==0) line=1;
  var upHeight=0-line*lineH;
  var liCount=_this.find("li").length;//LI的總數(shù)
  var showCount=parseInt(this.height()/lineH);//顯示出來(lái)的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如何實(shí)現(xiàn)中獎(jiǎng)播報(bào)功能

以上是“jQuery如何實(shí)現(xiàn)中獎(jiǎng)播報(bào)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(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)容。

AI