(function($) { $.fn.extend({ Scroll: function(opt, callback) { var sc = new RunScroll({ name: this.attr('id'), line: opt.line, column: opt.column, speed: opt.speed, timer: opt.timer, action:opt.action }); sc.Run(); } }) })(jQuery); var __ScrollTimeID={}; function RunScroll(pJso) { _.init(this,pJso,{ line:1, column:1, speed:800, timer:5000, name:'', action:'Top' }); if(!this.name) { alert('Unspecified tagID [name].') } this.jq=$('#'+this.name); } RunScroll.prototype = { Run: function() { var _this = this.jq.eq(0); //.find("ul:first"); var lineH; var line; if (this.action == 'Top' || this.action == 'Bottom') { lineH = _this.find("li:first").height(); //获取行高 line = this.line ? parseInt(this.line, 10) : parseInt(this.jq.height() / lineH, 10); } else { lineH = _this.find("li:first").width(); //获取行高 line = this.line ? parseInt(this.line, 10) : parseInt(this.jq.width() / lineH, 10); } var speed = this.speed ? parseInt(this.speed, 10) : 500; //卷动速度,数值越大,速度越慢(毫秒) var timer = this.timer ? parseInt(this.timer, 10) : 3000; //滚动的时间间隔(毫秒) var lineColumn = this.column ? parseInt(this.column, 10) : 1; //每行显示几列 if (line == 0) line = 1; var upHeight = -line * lineH / lineColumn; var animateAction; var animateAction1; switch (this.action) { case 'Top': animateAction = { marginTop: upHeight }; animateAction1 = { marginTop: 0 }; break; case 'Bottom': animateAction = { marginBottom: upHeight }; animateAction1 = { marginBottom: 0 }; break; case 'Left': animateAction = { marginLeft: upHeight }; animateAction1 = { marginLeft: 0 }; break; case 'Right': animateAction = { marginRight: upHeight }; animateAction1 = { marginRight: 0 }; break; } var scrollUp = function() { _this.animate(animateAction, speed, function() { for (i = 1; i <= line; i++) { _this.find("li:first").appendTo(_this); } _this.css(animateAction1); }); } //鼠标事件绑定 _this.hover(function() { clearInterval(this.timeID); }, function() { this.timeID = setInterval(scrollUp, timer); }).mouseout(); } } //run $(function () { var o = $('*[fname=Scrool]'); if (o.length == 0) { return; } o = o[0]; eval('var fjson=' + $(o).attr('fdata')); $(o).Scroll(fjson); });