(function ($) {
$.fn.extend({
Scroll: function (opt, callback) {
//参数初始化
if (!opt) var opt = {};
var _this = this.eq(0).find("ul:first");
var direction = opt.direction;
var lineH;
var line = parseInt(opt.line, 10);
var row = parseInt(opt.row, 10);
if (line == 0) line = 1;
if (row == 0) row = 1;
var scrollUp;
var num = _this.children().length;
if (direction == "up") {
lineH = opt.itemWorH;
if (lineH <= 0)
lineH = _this.find("li:first").height(); //获取行高
var tmp = Math.floor(num / row);
_this.css("height", tmp * lineH);
//if (lineH <= 0) lineH = opt.itemWorH;
//var marginTop = _this.find("li:first").css("margin-Top");
//alert(marginTop)
var upHeight = 0 - line * lineH;
scrollUp = function () {
_this.animate({
marginTop: upHeight
}, speed, function () {
for (i = 1; i <= line * row; i++) {
_this.find("li:first").appendTo(_this);
}
_this.css({ marginTop: opt.margin });
});
}
}
else {
lineH = opt.itemWorH;
if (lineH <= 0)
lineH = _this.find("li:first").width(); //获取行宽
var tmp = Math.floor(num / line);
_this.css("width", tmp * lineH);
var upHeight = 0 - row * lineH;
//滚动函数
scrollUp = function () {
_this.animate({
"marginLeft": upHeight
}, speed, function () {
for (i = 1; i <= row; i++) {
_this.find("li:first").appendTo(_this);
}
_this.css({ "marginLeft": opt.margin });
});
}
}
speed = opt.speed ? parseInt(opt.speed, 10) : 3000, //卷动速度,数值越大,速度越慢(毫秒)
timer = opt.timer ? parseInt(opt.timer, 10) : 3000; //滚动的时间间隔(毫秒)
//鼠标事件绑定
// _this.hover(function () {
// clearInterval(timerID);
// }, function () {
timerID = setInterval(scrollUp, timer);
// }).mouseout();
}
})
})(jQuery);
用法
$("#could").Scroll({ line: 1, row: 3, speed: 3000, timer: 5000, direction: "left", margin: 0, itemWorH: 209 });
<div id="could" class="wCrank" style="display:none">
<ul>
<li class="move"><a href="#"><img width="174px" height="140px" src="20730031113_0362..jpg" onerror="this.src='/images/photo/mo.jpg'"/></a>
</li>
</ul></div>
浙公网安备 33010602011771号