我正在使用下面的代码构建一个插件。如果我将 $(opts.section, this).animate 更改为 $(opts.section).animate 它也可以按我的意愿工作,但是它会为 section 元素的所有实例设置动画,并且我希望它只影响当前的. 一旦我将“这个”添加到它,它就会停止一起工作。
$('.next', this).on({
click: function() {
if(count+2 <= totalElems) {
count += 1;
currentAnimationSpot += singleElem + opts.offset;
$(opts.section, this).animate({
left: -currentAnimationSpot
});
}
}
});
$('.prev', this).on({
click: function(){
if(count != 1) {
count-=1;
currentAnimationSpot -= singleElem + opts.offset;
$(opts.section, this).animate({
left: -currentAnimationSpot
});
}
}
});