87,907
社区成员
发帖
与我相关
我的任务
分享
(function ($) {
$.fn.myScroll = function (options) {
//默认配置
var defaults = {
speed: 40, //滚动速度,值越大速度越慢
rowHeight: 24, //每行的高度
delay: 1000 //滚动每行后停留多少时间,单位ms
};
var opts = $.extend({}, defaults, options), intId = [],delayId=[];
function startAnimate(i,_this) {
intId[i] = setInterval(function () {
if (_this.find("ul").height() <= _this.height()) {
clearInterval(intId[i]);
} else {
marquee(_this, opts.rowHeight, i);
}
}, options.speed);
}
function marquee(obj, step,i) {
obj.find("ul").animate({
marginTop: '-=1'
}, 0, function () {
var s = Math.abs(parseInt($(this).css("margin-top")));
if (s >= step) {
clearInterval(intId[i]);
delayId[i] = setTimeout(function () { startAnimate(i, obj); }, opts.delay);
$(this).find("li").slice(0, 1).appendTo($(this));
$(this).css("margin-top", 0);
}
});
}
this.each(function (i) {
var _this = $(this);
startAnimate(i, _this);
/////
_this.hover(function () { clearTimeout(delayId[i]); clearInterval(intId[i]); }, function () { startAnimate(i, _this); });
});
}
})(jQuery);