var enabled = true; var i = parseInt($("#screenshotCount").val()); $("#screenshots").css("width", i * 768); $("#screenshotBox").mouseenter(function() { $(".scrollButton").stop().fadeTo(400, 1); window.clearInterval(autoscroll); }).mouseleave(function() { $(".scrollButton").stop().fadeTo(400, 0); autoscroll = window.setInterval(scrollRight, 5000); }); var scrollLeft = function() { if(!enabled) return; enabled = false; $("#screenshots").prepend($(".screenshot:last")).css("left", "-768").animate({left: 0}, 400, function() {enabled = true;}); }; var scrollRight = function() { if(!enabled) return; enabled = false; $("#screenshots").animate({left: "-768px"}, 400, function() { $("#screenshots").append($(".screenshot:first")).css("left", 0); enabled = true; }); }; $("#scrollLeft").on("click", scrollLeft); $("#scrollRight").on("click", scrollRight); var autoscroll = window.setInterval(scrollRight, 5000);