基于jquery的无缝循环新闻列表

港控/mmm° 2022-04-13 14:11 290阅读 0赞

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





<br> 无缝循环新闻列表<br>
















/*
* write by waitingbar
* time 2011.03.04
*
*/

(function($) {
$.fn.extend({
newsList: function(options) {
var defaults = {
actName: ‘li’,
//显示条数名;
maxShowNum: ‘6’,
//最多的显示条数;
actNameH: ‘28’,
//一次移动的距离;
ulClass: ‘.ul_news_list’,
//被复制层的class
copyUlClass: ‘.ul_news_list2’,
//复制层的class
autoTime: ‘1500’,
//自动运行时间;
clickGoUpC: ‘.go_uplist’,
//点击向上class;
clickDownUpC: ‘.go_downlist’,
//点击向下class;
goStart: ‘go_tart’,
autoCloss: ‘flase’ //自动运行开关,当为’flase’时为开,其它则关;
}

  1. options = $.extend(defaults, options);
  2. return this.each(function() \{
  3. var o = options;
  4. var counts = 1;
  5. var linum = $($(this).find(o.actName), $(this)).size();
  6. var ul\_class = $($(this).find(o.ulClass), $(this));
  7. var copy\_ul\_class = $($(this).find(o.copyUlClass), $(this));
  8. var click\_go\_up\_c = $($(this).find(o.clickGoUpC), $(this));
  9. var click\_go\_down\_C = $($(this).find(o.clickDownUpC), $(this));
  10. var go\_start = $($(this).find(o.goStart), $(this));
  11. if (linum > o.maxShowNum) \{
  12. $(copy\_ul\_class).html($(ul\_class).html());
  13. goStartList();
  14. \}
  15. var thiswrap = $($(ul\_class).parent().parent(), $(this));
  16. //自动运行函数
  17. function auto\_function() \{
  18. if (counts <= linum) \{
  19. $(ul\_class).animate(\{
  20. top: '-=' + o.actNameH
  21. \},
  22. o.autoTime);
  23. $(copy\_ul\_class).animate(\{
  24. top: '-=' + o.actNameH
  25. \},
  26. o.autoTime);
  27. counts++;
  28. \} else \{
  29. $(ul\_class).animate(\{
  30. top: 0
  31. \},
  32. 0);
  33. $(copy\_ul\_class).animate(\{
  34. top: 0
  35. \},
  36. 0);
  37. counts = 1;
  38. \}
  39. \}
  40. //点击向上移动时;
  41. if (linum > o.maxShowNum) \{
  42. $(click\_go\_up\_c).click(function() \{
  43. if (counts <= linum) \{
  44. $(ul\_class).animate(\{
  45. top: '-=' + o.actNameH
  46. \},
  47. 0);
  48. $(copy\_ul\_class).animate(\{
  49. top: '-=' + o.actNameH
  50. \},
  51. 0);
  52. counts++;
  53. \} else \{
  54. $(ul\_class).animate(\{
  55. top: 0
  56. \},
  57. 0);
  58. $(copy\_ul\_class).animate(\{
  59. top: 0
  60. \},
  61. 0);
  62. counts = 1;
  63. \}
  64. \});
  65. \}
  66. //点击向下移动时;
  67. if (linum > o.maxShowNum) \{
  68. $(click\_go\_down\_C).click(function() \{
  69. if (counts > 1) \{
  70. counts--;
  71. $(ul\_class).animate(\{
  72. top: '-' + counts \* o.actNameH
  73. \},
  74. 0);
  75. $(copy\_ul\_class).animate(\{
  76. top: '-' + counts \* o.actNameH
  77. \},
  78. 0);
  79. \} else \{
  80. $(ul\_class).animate(\{
  81. top: 0
  82. \},
  83. 0);
  84. $(copy\_ul\_class).animate(\{
  85. top: 0
  86. \},
  87. 0);
  88. counts = linum + 1;
  89. \}
  90. \});
  91. \}
  92. //鼠标经过所发生的开始停止;
  93. if (linum > o.maxShowNum) \{
  94. $(thiswrap).hover(function() \{
  95. goStopList();
  96. \},
  97. function() \{
  98. goStartList();
  99. \});
  100. \}
  101. function goStartList() \{
  102. if (o.autoCloss === 'flase') \{
  103. go\_start = setInterval(auto\_function, o.autoTime);
  104. \}
  105. \}
  106. function goStopList() \{
  107. clearInterval(go\_start);
  108. \}
  109. \});
  110. \}
  111. \});

} (jQuery));

@charset “utf-8”;
/* CSS Document */
body { font-family:”微软雅黑”,Arial,”Lucida Grande”, Verdana, Lucida; font-size:12px; }
*{ padding:0; margin:0;}
img { border:0;}
.clear { clear:both;}
a { color:#000; text-decoration:none;}
a:hover { color:#EC6104; text-decoration:none;}
.undis { display:none;}/*news_list*/
.news_list_bar { position:relative; width:560px; height:168px; overflow:hidden; background:url(../images/slideshow2/v3_picture6.gif) repeat-y; background-color:#F00;}
.ul_news_list,
.ul_news_list2{ position:relative; list-style:none;}
.ul_news_list li,
.ul_news_list2 li{line-height:28px; height:28px; width:500px; overflow:hidden; white-space:nowrap;padding:0 20px;}
.ul_news_list li a,
.ul_news_list2 li a{ padding-right:20px;}
.go_upanddown { position:absolute; margin:-20px 0 0 500px;}
.go_upanddown span { padding-right:10px; cursor:pointer;}

发表评论

表情:
评论列表 (有 0 条评论,290人围观)

还没有评论,来说两句吧...

相关阅读