87,904
社区成员
发帖
与我相关
我的任务
分享
<!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);
}
}
});
//向右滚动
jQuery(this).find('.btnRight').click(function(){
if (!showbox.is(':animated')) {
if (positionleft == -w * (page_count - 1)) {
positionleft=0;
showbox.animate({
left: 0
}, 500);
}else {
positionleft=positionleft-w;
showbox.animate({
left:positionleft
}, 500);
}
}
});
}
</script>
</head>
<body>
<div class="newlistdiv">
<div class="btnLeft"></div>
<div class="btnRight"></div>
<div class="newcnt">
<div class="newlist">
<div class="newtextall">
1
</div>
<div class="newtextall">2
</div>
<div class="newtextall">3
</div>
<div class="newtextall">4
</div>
<div class="newtextall">5
</div>
</div>
</div>
</div>
</body>
</html>
//向左滚动
jQuery(this).find('.btnLeft').click(function () {
if (!showbox.is(':animated')) {
if (positionleft == 0) {
positionleft = positionleft - w * (page_count - 1);
showbox.css('left', positionleft);//////////////
/*showbox.animate({
left: positionleft
}, 500);*/
} else {
positionleft = positionleft + w
showbox.animate({
left: positionleft
}, 500);
}
}
});
//向右滚动
jQuery(this).find('.btnRight').click(function () {
if (!showbox.is(':animated')) {
if (positionleft == -w * (page_count - 1)) {
positionleft = 0;
showbox.css('left', 0);////////////////
/*showbox.animate({
left: 0
}, 500);*/
} else {
positionleft = positionleft - w;
showbox.animate({
left: positionleft
}, 500);
}
}
});