<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript"> <BR>(function ($) { <BR>$.fn.extend({ <BR>Scroll: function (opt, callback) { <BR>if (!opt) var opt = {}; <BR>var _btnleft = $(opt.left); <BR>var _btnright = $(opt.right); <BR>var timerID; <BR>var _this = this.eq(0).find("div").eq(1); <BR>var lineW = _this.find("a:first").width(), //获取列宽 <BR>line = opt.line ? parseInt(opt.line, 10) : parseInt(_this.width() / lineW, 10), //每次滚动的列数,默认为一屏,即父容器列宽 <BR>speed = opt.speed ? parseInt(opt.speed, 10) : 500; //滚动速度,数值越大,速度越慢(毫秒) <BR>timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滚动的时间间隔(毫秒) <BR>if (line == 0) line = 1; <BR>var upWidth = 0 - line * lineW; <BR>//滚动函数 <BR>var scrollLeft = function () { <BR>if (!_this.is(":animated")) { <BR>_this.animate({ <BR>left: upWidth <BR>}, speed, function () { <BR>for (i = 1; i <= line; i++) { <BR>_this.find("a:first").appendTo(_this); <BR>} <BR>_this.css({ left: 0 }); <BR>}); <BR>} <BR>} <BR>var scrollRight = function () { <BR>if (!_this.is(":animated")) { <BR>for (i = 1; i <= line; i++) { <BR>_this.find("a:last").show().prependTo(_this); <BR>} <BR>_this.css({ left: upWidth }); <BR>_this.animate({ <BR>left: 0 <BR>}, speed, function () { <BR>}); <BR>} <BR>} //Shawphy:自动播放 <BR>var autoPlay = function () { <BR>if (timer) timerID = window.setInterval(scrollLeft, timer); <BR>}; <BR>var autoStop = function () { <BR>if (timer) window.clearInterval(timerID); <BR>}; //鼠标事件绑定 <BR>_this.hover(autoStop, autoPlay).mouseout(); <BR>_btnleft.css("cursor", "pointer").click(scrollLeft).hover(autoStop, autoPlay); <BR>_btnright.css("cursor", "pointer").click(scrollRight).hover(autoStop, autoPlay); <BR>} <BR>}) <BR>})(jQuery); <BR>$(document).ready(function () { <BR>$("#scrollable").Scroll({ line: 5, speed: 500, timer: 3000, left: ".prev", right: ".next"}); <BR>}); <BR></script>
说明:1、需要两个图片
left.png:

right.png:

2、需要引入jquery的包,这个应该不用说的...... <script src="http://www.cnblogs.com/yunduan/admin/jquery-1.3.1.js" type="text/javascript"></script><script language="javascript" type="text/javascript">// <![CDATA[ (function ($) { $.fn.extend({ Scroll: function (opt, callback) { //参数初始化 if (!opt) var opt = {}; var _btnleft = $(opt.left); var _btnright = $(opt.right); var timerID; var _this = this.eq(0).find("div").eq(1); var lineW = _this.find("a:first").width(), //获取列宽 line = opt.line ? parseInt(opt.line, 10) : parseInt(_this.width() / lineW, 10), //每次滚动的列数,默认为一屏,即父容器列宽 speed = opt.speed ? parseInt(opt.speed, 10) : 500; //卷动速度,数值越大,速度越慢(毫秒) timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滚动的时间间隔(毫秒) if (line == 0) line = 1; var upWidth = 0 - line * lineW; //滚动函数 var scrollLeft = function () { if (!_this.is(":animated")) { _this.animate({ left: upWidth }, speed, function () { for (i = 1; i <= line; i++) { _this.find("a:first").appendTo(_this); } _this.css({ left: 0 }); }); } } var scrollRight = function () { if (!_this.is(":animated")) { for (i = 1; i <= line; i++) { _this.find("a:last").show().prependTo(_this); } _this.css({ left: upWidth }); _this.animate({ left: 0 }, speed, function () { }); } } //Shawphy:自动播放 var autoPlay = function () { if (timer) timerID = window.setInterval(scrollLeft, timer); }; var autoStop = function () { if (timer) window.clearInterval(timerID); }; //鼠标事件绑定 _this.hover(autoStop, autoPlay).mouseout(); _btnleft.css("cursor", "pointer").click(scrollLeft).hover(autoStop, autoPlay); //Shawphy:向上向下鼠标事件绑定 _btnright.css("cursor", "pointer").click(scrollRight).hover(autoStop, autoPlay); } }) })(jQuery); $(document).ready(function () { $("#scrollable").Scroll({ line: 5, speed: 500, timer: 3000, left: ".prev", right: ".next"}); }); // ]]></script>


















