Jquery实现图片左右滚动,没有头尾的,一直循环。这样子的例子我已经发了很多了,这边放两个链接
http://www.corange.cn/archives/2010/06/3654.html
http://www.corange.cn/archives/2010/06/3649.html
http://www.corange.cn/archives/2010/06/3650.html
等等,如果你多访问本站,会发现很多好东西,呵呵。
<!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>www.corange.cn</title>
<style type="text/css">
<!--
*{margin:0; padding:0}
li{list-style:none}
img{border:0}
body{background-color:#fff; font-size:12px; color:#2c2c2c; font-family:Arial, Helvetica, sans-serif}
a{color:#444; text-decoration:none}
a:hover{color:#900; text-decoration:underline}
.con{overflow:hidden; margin:30px auto; width:442px; height:100%; padding:10px 15px; border:solid 1px #FCBA79; background-color:#FFFBEC;}
#carousel_container{position:relative; height:100px; overflow:hidden;}
#carousel_inner{width:391px; height:95px; overflow: hidden; position:absolute;left:25px; top:5px;}
#left_scroll{position: absolute;left:0;top:43px;width:9px;height:9px;cursor: pointer;cursor: hand; background:url(http://www.cnblogs.com/images/cnblogs_com/chenjmdg/left.gif) no-repeat;}
#right_scroll{position: absolute;top:43px;right:0; width: 9px;height: 9px;cursor: pointer;cursor: hand; background: url(http://www.cnblogs.com/images/cnblogs_com/chenjmdg/right.gif) no-repeat;}
#carousel_ul{width:9999px; height:95px; position:relative;}
#carousel_ul li{float: left;width:84px; height:86px; border:solid 1px #FEDDAB; margin-right:15px; display:inline;}
-->
</style>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
var SellerScroll = function(options){
this.SetOptions(options);
this.lButton = this.options.lButton;
this.rButton = this.options.rButton;
this.oList = this.options.oList;
this.showSum = this.options.showSum;
this.iList = $("#" + this.options.oList + " > li");
this.iListSum = this.iList.length;
this.iListWidth = this.iList.outerWidth(true);
this.moveWidth = this.iListWidth * this.showSum;
this.dividers = Math.ceil(this.iListSum / this.showSum);//共分为多少块
this.moveMaxOffset = (this.dividers - 1) * this.moveWidth;
this.LeftScroll();
this.RightScroll();
};
SellerScroll.prototype = {
SetOptions: function(options){
this.options = {
lButton: "left_scroll",
rButton: "right_scroll",
oList: "carousel_ul",
showSum: 4//一次滚动多少个items
};
$.extend(this.options, options || {});
},
ReturnLeft: function(){
return isNaN(parseInt($("#" + this.oList).css("left"))) ? 0 : parseInt($("#" + this.oList).css("left"));
},
LeftScroll: function(){
if(this.dividers == 1) return;
var _this = this, currentOffset;
$("#" + this.lButton).click(function(){
currentOffset = _this.ReturnLeft();
if(currentOffset == 0){
for(var i = 1; i <= _this.showSum; i++){
$(_this.iList[_this.iListSum - i]).prependTo($("#" + _this.oList));
}
$("#" + _this.oList).css({ left: -_this.moveWidth });
$("#" + _this.oList + ":not(:animated)").animate( { left: "+=" + _this.moveWidth }, { duration: "slow", complete: function(){
for(var j = _this.showSum + 1; j <= _this.iListSum; j++){
$(_this.iList[_this.iListSum - j]).prependTo($("#" + _this.oList));
}
$("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 1) });
} } );
}else{
$("#" + _this.oList + ":not(:animated)").animate( { left: "+=" + _this.moveWidth }, "slow" );
}
});
},
RightScroll: function(){
if(this.dividers == 1) return;
var _this = this, currentOffset;
$("#" + this.rButton).click(function(){
currentOffset = _this.ReturnLeft();
if(Math.abs(currentOffset) >= _this.moveMaxOffset){
for(var i = 0; i < _this.showSum; i++){
$(_this.iList[i]).appendTo($("#" + _this.oList));
}
$("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 2) });
$("#" + _this.oList + ":not(:animated)").animate( { left: "-=" + _this.moveWidth }, { duration: "slow", complete: function(){
for(var j = _this.showSum; j < _this.iListSum; j++){
$(_this.iList[j]).appendTo($("#" + _this.oList));
}
$("#" + _this.oList).css({ left: 0 });
} } );
}else{
$("#" + _this.oList + ":not(:animated)").animate( { left: "-=" + _this.moveWidth }, "slow" );
}
});
}
};
$(document).ready(function(){
var ff = new SellerScroll();
});
//-->
</script>
</head>
<body>
<div class="con">
<div id="carousel_container">
<div id="left_scroll"></div>
<div id="carousel_inner">
<ul id="carousel_ul">
<li>www.corange.cn</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
</ul>
</div>
<div id="right_scroll"></div>
</div>
</div>
</body>
</html>
原文地址:http://www.corange.cn/archives/2010/08/3682.html
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)