成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jQuery滾動新聞實現代碼
全站頭部文字 我要出現在這里
jQuery滾動新聞實現代碼 610 2024-02-26   

網上下載了一個Jquery新聞滾動Demo,效果不錯。我根據自己情況,做了些調整。
下載后,除了Html及Jquery.js,還有三個文件,分別是Css,主Js和一個定位Js(jquery.dimensions.js),Css文件完全可以通過動態賦值實現,省的在Css文件中添加了,況且可以重定義,應該效果更好。
定位Js只用到一個方法,我把它整合到之中了,少加載一個是一個么。
原Demo是一行顯示的滾動效果,有一個Bug,即不等的多行顯示時會跑錯,已修復。
原Demo有一個mouseover屬性,我一般不用(效果不好,看一下實現方法也有漏洞,在多行時效果更差),刪除了。

借鑒別人的思路與代碼,不敢獨享。

刪除的部分:

   $('> ul', this)
    .bind('mouseover', function(e) {
     if ($(e.target).is('li')) {
      $(e.target).addClass('hover');
     }
    })
    .bind('mouseout', function(e) {
     if ($(e.target).is('li')) {
      $(e.target).removeClass('hover');
     }
    });

調整后代碼:

html部分:

<div id="tbNews">
<ul>
 <li>1、滾動新聞,滾動新聞,滾動新聞,滾動新聞,滾動新聞</li>
 <li>2、滾動新聞,滾動新聞</li>
 <li>3、滾動新聞,滾動新聞,滾動新聞,滾動新聞</li>
 <li>4、滾動新聞,滾動新聞,滾動新聞,滾動新聞,滾動新聞</li>
 <li>5、滾動新聞</li>
</ul>
</div>
<script language="JavaScript" src="http://www.gimoo.net/t/1901/jdNewsScroll.js" type="text/javascript">
</script>
<script defer="defer" language="JavaScript" type="text/javascript">
$(function() {
 $('#tbNews').jdNewsScroll({divWidth:130,divHeight:50,fontSize:'10.5pt'});
});
</script>

Js代碼:

(function($){
  var ELMS = [];
  $.fn.jdNewsScroll = function(settings) {
  settings = $.extend({}, arguments.callee.defaults, settings);
 $(this).css({"position":"relative","overflow":"hidden","width":settings.divWidth,"height":settings.divHeight});
 $(this).find("ul").css({"position":"relative","list-style-type":"none","font-size":settings.fontSize,"margin":"0px"});
 $(this).find("li").css({"line-height":"130%","margin":"0px","padding":"2px 10px 1px 10px"});
  $(this).each(function(){
   this.$settings = settings;
   this.$pause = false;
   this.$counter = settings.beginTime;
   $(this).hover(function(){ $(this).jdNewsScrollPause(true) }, function(){ $(this).jdNewsScrollPause(false) });
   ELMS.push(this);
  });
  return this;
 };
 $.fn.jdNewsScroll.defaults = {
  beginTime: 10,
  fontSize: '9pt',
  divWidth: '100%',
  divHeight: '200px',
  lineHeight: '130%',
  delay:  20,
  step: 2
 };
 $.fn.jdNewsScrollPause = function(pause) {
  return this.each(function() {
   this.$pause = pause;
  });
 }
 function outerHeight(options) {
  if (!this[0]) 0;
  options = $.extend({ margin: false }, options || {});
  return this[0] == window || this[0] == document ?
   this.height() : this.is(':visible') ?
    this[0].offsetHeight + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0) :
    this.height() 
     + num(this,'borderTopWidth') + num(this, 'borderBottomWidth') 
     + num(this, 'paddingTop') + num(this, 'paddingBottom')
     + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0);
 }

 setInterval(scroll, 80);
 function scroll() {
  for (var i = 0; i < ELMS.length; i++) {
   var elm = ELMS[i];
   if (elm && !elm.$pause) {
    if (elm.$counter == 0) {
     var ul  = $('> ul', elm)[0];
     if (!elm.$steps) {
      elm.$steps = $('> li:first-child', ul).outerHeight();
      elm.$step = 0;
     }
     if ((elm.$steps + elm.$step) <= 0) {
      elm.$counter  = elm.$settings.delay;
      elm.$steps   = false;
      $(ul).css('top', '0').find('> li:last-child').after($('> li:first-child', ul));
      $('> *', ul).not('li').remove();
     } else {
      elm.$step -= elm.$settings.step;
      if (-elm.$step > elm.$steps) {
       elm.$step = -elm.$steps;
      }
      ul.style.top = elm.$step + 'px';
     }
    } else {
     elm.$counter--;
    }
   }
  }
 };
})(jQuery);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持綠夏網。



主站蜘蛛池模板: 成人在线免费观看电影| 折叠画| 男同操男同| 高冷女头| rima horton| 女医生韩国| 巢谷传| 午夜魅影| 红尾鱼图片| 寄宿生韩国电影| 玫瑰情人| 春江英雄之秀才遇到兵| 荆棘花| 阮经天新电影| 流浪地球2视频免费播放下载 | 第九区电影免费观看完整版 | a friend in need中文翻译| 美女不穿衣服| 周岁封酒| 阴道电影| 萱草花合唱谱二声部| 郑艳丽三级| 陈冠希的艳照门| 生死瞬间演员表| lanarhoades无套大片| 忏悔三昧念3遍| 欢迎来到nhk| 闪电小子| 电影暗夜| 韩国成人网| 视频污| 爱情颂歌| junk boy| 1998年槟榔西施| 徐少强全部电影| 纳尼亚传奇4在线观看免费完整版 虞书欣新剧永夜星河免费观看 | 那些女人演员表全部名单| 神探狄仁杰1电视剧 | 美女抠逼喷水视频| 爱情心心相印| 引诱|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103