スライダーを作成しました。正常に自動再生され、ホバーで一時停止し、ぼかしで再開します。偉大な。
しかし、クリックすると、新しい間隔が開始され、2倍の速さで進み、クリアできませんか?
これが私のコードです:
// Reset autoPlay() if a user clicks a nav button
$('#sliderNav a').click(function(e) {
setTimeout(autoPlay(), delay);
});
// Auto play the slider
var delay = 4000; // 4 seconds
function autoPlay() {
myInterval = setInterval(function() {
currentOffset += itemWidths[clickCount] // Add the current slides width to total offset
$sliderWrap.animate({right: currentOffset}, 500, function() {
clickCount++;
// If this is the last slide when clicking .next, slide to clone then snap back to beginning.
if ( itemWidths.length == clickCount ) {
clickCount = 0;
currentOffset = totalWidth;
$sliderWrap.css('right',currentOffset); // Where we started originally
}
});
}, delay );
}
autoPlay();
// Stop autoPlay() on hover
$('#slider, #sliderNav a').hover(function() {
clearInterval(myInterval);
},
// start autoPlay() on blur
function() {
autoPlay();
});
実際に動作するデモを実際に見ることができます: http://www.jonheslop.com/canoe/