我有一个图像库,由两行5个图像组成,共10个图像。我将拥有20张图像,并且当用户按下下一个按钮时,图库会移动到下面的10张图像,之前用户被带到之前的10张图像。对于我的生活,我无法弄清楚为什么我的上一个和下一个按钮不起作用。图库上一个和下一个按钮不起作用
的jQuery:
var $item = $('div.folder'), //Cache your DOM selector
visible = 5, //Set the number of items that will be visible
index = 0, //Starting index
endIndex = ($item.length/visible) - 1; //End index
$('div#arrowR-spring').click(function() {
if (index < endIndex) {
index++;
$item.animate({
'left': '-=315px'
});
} else {
index = 0;
$item.animate({
'left': '+=' + (315 * endIndex) + 'px'
});
}
});
$('div#arrowL-spring').click(function() {
if (index > 0) {
index--;
$item.animate({
'left': '+=315px'
});
} else {
index = endIndex;
$item.animate({
'left': '-=' + (315 * endIndex) + 'px'
});
}
});
这是我目前有:link to my fiddle。任何帮助将不胜感激!
namkaha感谢您的回应....我如何设置动画的速度?谢谢! – jsavage980 2013-03-12 13:00:38
@ jsavage980:使用$ item.animate({'margin-left':' - = 315'},300); – phnkha 2013-03-12 13:13:25
感谢您的帮助namkaha!非常感激!! – jsavage980 2013-03-12 13:48:17