基于jquery的无缝循环新闻列表
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


/*
* 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’时为开,其它则关;
}
options = $.extend(defaults, options);
return this.each(function() \{
var o = options;
var counts = 1;
var linum = $($(this).find(o.actName), $(this)).size();
var ul\_class = $($(this).find(o.ulClass), $(this));
var copy\_ul\_class = $($(this).find(o.copyUlClass), $(this));
var click\_go\_up\_c = $($(this).find(o.clickGoUpC), $(this));
var click\_go\_down\_C = $($(this).find(o.clickDownUpC), $(this));
var go\_start = $($(this).find(o.goStart), $(this));
if (linum > o.maxShowNum) \{
$(copy\_ul\_class).html($(ul\_class).html());
goStartList();
\}
var thiswrap = $($(ul\_class).parent().parent(), $(this));
//自动运行函数
function auto\_function() \{
if (counts <= linum) \{
$(ul\_class).animate(\{
top: '-=' + o.actNameH
\},
o.autoTime);
$(copy\_ul\_class).animate(\{
top: '-=' + o.actNameH
\},
o.autoTime);
counts++;
\} else \{
$(ul\_class).animate(\{
top: 0
\},
0);
$(copy\_ul\_class).animate(\{
top: 0
\},
0);
counts = 1;
\}
\}
//点击向上移动时;
if (linum > o.maxShowNum) \{
$(click\_go\_up\_c).click(function() \{
if (counts <= linum) \{
$(ul\_class).animate(\{
top: '-=' + o.actNameH
\},
0);
$(copy\_ul\_class).animate(\{
top: '-=' + o.actNameH
\},
0);
counts++;
\} else \{
$(ul\_class).animate(\{
top: 0
\},
0);
$(copy\_ul\_class).animate(\{
top: 0
\},
0);
counts = 1;
\}
\});
\}
//点击向下移动时;
if (linum > o.maxShowNum) \{
$(click\_go\_down\_C).click(function() \{
if (counts > 1) \{
counts--;
$(ul\_class).animate(\{
top: '-' + counts \* o.actNameH
\},
0);
$(copy\_ul\_class).animate(\{
top: '-' + counts \* o.actNameH
\},
0);
\} else \{
$(ul\_class).animate(\{
top: 0
\},
0);
$(copy\_ul\_class).animate(\{
top: 0
\},
0);
counts = linum + 1;
\}
\});
\}
//鼠标经过所发生的开始停止;
if (linum > o.maxShowNum) \{
$(thiswrap).hover(function() \{
goStopList();
\},
function() \{
goStartList();
\});
\}
function goStartList() \{
if (o.autoCloss === 'flase') \{
go\_start = setInterval(auto\_function, o.autoTime);
\}
\}
function goStopList() \{
clearInterval(go\_start);
\}
\});
\}
\});
} (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;}
还没有评论,来说两句吧...