一、:
tips源碼下載 http://xiazai.jb51.net/201103/yuanma/jquerynewslist.rar
二、jquery源碼:
複製代碼 代碼如下:
(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));
三、HTML:
複製代碼 代碼如下:
<script language="javascript">
$(document).ready(function(){
$("#newslist").newsList();
});
</script>
<div id="newslist">
<div class="go_upanddown"><span class="go_uplist"><img src="images/newslist/goupbtn.gif" /></span><span class="go_downlist"><img src="images/newslist/godownbtn.gif" /></span></div>
<div class="news_list_bar">
<ul class="ul_news_list">
<li><a href="#">1、曾參加過唐山、汶川、玉樹地震救援的援</a><a href="#">曾參加過唐,又來到了舟曲參加救援</a></li>
<li><a href="#">2、摩洛哥塞拉,藝術家在一場為流浪兒童為流浪兒童為流浪兒童為流浪兒童募捐的馬戲節目中表演</a></li>
<li><a href="#">3、昆明警方近日縣的“洪興甸縣的“洪興甸縣的“洪興甸縣的“洪興幫”黑惡勢力團夥,繳獲...</a></li>
<li><a href="#">4、印度克什知自己的孩子在騷亂中喪生時痛不欲生..</a><a href="#">曾參加過唐曾參加過唐到了舟曲參加救援</a></li>
<li><a href="#">5、明昆明警方近日搗毀了尋甸縣的“洪興幫”黑惡勢力團夥,繳獲...</a></li>
<li><a href="#">6、曾參加過唐曾參加過唐曾參加過唐曾參加過唐</a></li>
<li><a href="#">7、湖北武漢漢口漢口曾參加過唐曾參加過唐曾參加過唐曾參加過唐觀看兩江洪峰過</a></li>
<li><a href="#">8、湖北武漢漢曾參加過唐曾參加過唐曾參加過唐曾參加過唐集在江邊觀</a></li>
<li><a href="#">9、湖北武漢漢口漢口龍王廟景區觀景平台上,市民聚集在江邊觀看兩江洪峰過漢</a></li>
</ul>
<ul class="ul_news_list2"></ul>
</div>
</div>
四、CSS:
複製代碼 代碼如下:
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;}