我真正想要实现的是检测div何时滚动到结尾并因此将其返回到div的开头。当div自动滚动时,我想将左边设置为0,因此返回到div的开头,当div由prev控制时,下一个按钮在到达左边时停止,当它到达时为止右端。但是我能得到的所有小代码就是左右滚动但是当它结束时可以阻止它,任何有关如何做到这一点的帮助将不胜感激,谢谢
var sliderWidth = $(".dialyDealSlider").width();
var ddslider = $(".dialyDealSlider");
var BoxWidth = $(".dialyDealBox").width();
$(".ddslider-prev").click(function() {
//alert(BoxWidth);
var leftPos = ddslider.scrollLeft();
var newWidth = leftPos - BoxWidth;
alert(BoxWidth);
ddslider.animate({
left: "-=" + newWidth + "px"
}, 800);
});
$(".ddslider-next").click(function() {
//alert('next');
var leftPos = ddslider.scrollLeft();
var newWidth = leftPos + BoxWidth;
alert(newWidth);
ddslider.animate({
left: "-=" + newWidth + "px"
}, 800);
});
dailyDeal();
function dailyDeal(finalWidth) {
var timer;
clearTimeout(timer);
scrollWidth = $(".dialyDealBox").width();
leftPosi = $(".dialyDealSlider").scrollLeft();
scrollWidth = leftPosi + scrollWidth;
$(".dialyDealSlider").animate({
left: "-=" + scrollWidth + "px"
}, 800);
timer = setTimeout(dailyDeal, 3000);
}
JS FIDDLE https://jsfiddle.net/sammyzeal/dcxvLgm0/