日期:2014-05-16 浏览次数:20476 次
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test2</title>
<style type="text/css">
.newlistdiv { width:565px; height:200px; padding:0 40px; position:relative; float:left;}
.newlistdiv .btnLeft { width:25px; height:40px; background:url(images/btnLeft.jpg) no-repeat; position:absolute; left:0px; top:80px;}
.newlistdiv .btnRight { width:25px; height:40px; background:url(images/btnRight.jpg) no-repeat; position:absolute; right:0px; top:80px;}
.newcnt { width:565px; height:200px; position:relative; overflow:hidden; }
.newcnt .newlist { width:800%; height:200px; position:absolute; top:0; left:0;}
.newlist .newtextall { width:565px; float:left; position:relative; z-index:0;height:200px;}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
jQuery(function(){
jQuery(".newlistdiv").each(function(){jQuery(this).news('.newcnt',1);});
})
jQuery.fn.news=function(parent_div,page_size){
var positionleft=0;
var o=jQuery(this).find(parent_div);
var w = o.width();
var showbox = jQuery(this).find('.newlist');
var len = showbox.find('.newtextall').length;
var page_count = Math.ceil(len / page_size);
showbox.width(w*page_count);
//向左滚动
jQuery(this).find('.btnLeft').click(function(){
if (!showbox.is(':animated')) {
if (positionleft == 0) {
positionleft=positionleft-w * (page_count - 1);
showbox.animate({
left:positionleft
}, 500);
} else {
positionleft=positionleft+w
showbox.animate({
left:positionleft
}, 500);
}
}
});