ストップ ライト アニメーション (赤から始まる回転点滅ライト > 黄 > 緑) を作成しようとしています。いずれかのライトにカーソルを合わせると、アニメーションが一時停止し、選択したライトが点灯し、ホバー div が表示されます。
これまでのところ、すべてが機能しています (ただし、コードで何らかの最適化を使用できると確信しています) が、いずれかのライトにカーソルを合わせても、アニメーションはすぐには停止しません。clearTimeout と clearInternal を使用してみましたが、何も機能していません。
jsfiddle: http://jsfiddle.net/JZ86B/
これが私のjQueryです
stopLight();
$('[class^="stopLight"]').mouseenter(function(){
clearTimeout(window.flashLightTimer);
clearInterval(window.stopLightInterval);
$(this).css('background-position-x','-106px');
$(this).find('span').fadeIn('fast');
}).mouseleave(function() {
$(this).css('background-position-x','0px');
$(this).find('span').hide('fast');
stopLight();
});
function stopLight() {
window.stopLightInterval = setInterval(function() {
flashLight('red',1000);
flashLight('yellow',2000);
flashLight('green',3000);
}, 3000);
};
function flashLight (a, b) {
window.flashLightTimer = setTimeout(function(){
$(".stopLight-"+a).animate({
'background-position-x': '-106px'
}, 0, 'linear')
.delay(1000)
.animate({
'background-position-x': '0px'
}, 0, 'linear')
}, b);
};