I think that you will miss the fact that when you do stop (), you are actually positioning the slider at a specific point. That is, if your scroller is 1000 pixels, and you double-click the left mouse button, you will probably get
scrollLeft: 0 - 251 scrollLeft: -2 - 251
So, I think you should use an index, not exactly these + = and - = calculations. For instance:
$(function () { var numberOfDivs = 7; var divWidth = 251; var currentIndex = 0; $("#right, #left").click(function () { currentIndex = this.id == "right" ? currentIndex+1 : currentIndex-1; currentIndex = currentIndex < 0 ? 0 : currentIndex; currentIndex = currentIndex > numberOfDivs ? numberOfDivs : currentIndex; $(".outerwrapper").stop().animate({ scrollLeft: (currentIndex * divWidth) + "px" }, 1000); }); });
The big advantage of this approach is that you don't turn off the click. You can click as many times as you want, and you can do it quickly. the script will work.
source share