我有这个,这是一个图像滑块,当它到达终点并返回时,它会继续转动:
$(function () {
var sliderUL = $('div.headslide').children('ul'),
imgs = sliderUL.find('img'),
imgWidth = imgs[0].width,
imgsLenth = imgs.length,
current = 1,
totalImgsWidth = imgsLenth * imgWidth,
direction = 'next',
loc = imgWidth,
interval = setInterval(swapBKgnd, 9000);
function swapBKgnd() {
(direction === 'next') ? ++current : --current;
if (current === 0) {
current = imgsLenth;
loc = totalImgsWidth - imgWidth;
direction = 'next';
} else if (current - 1 === imgsLenth) {
current = 1;
loc = 0;
}
transition(sliderUL, loc, direction);
};
function transition(container, loc, direction) {
var unit;
if (direction && loc !== 0 ) {
unit = (direction === 'next') ? '-=' : '+=';
}
container.animate({
'margin-left': unit ? (unit + loc) : loc,
});
}
});
它的意思是继续前进,但是一旦到达终点并回到第一个……它就停止了。我将如何解决这个问题?