2012-07-29 68 views
1

我想停止當前位置上的旋轉輪它在鼠標上使用jQueryRotate插件並繼續動畫旋轉的地方它在鼠標停止,停止jQueryRotate插件上mouseover當前位置並繼續mouseout

我似乎無法讓它與我的自定義動畫

工程紡車的代碼將在這裏jsfiddle

var angle = 0; 
    setInterval(function(){ 
     angle+=3; 
    $("#carwheel").rotate(angle,{ easing:'easeInOutElastic'}); 

    $("#carwheel") 
    .mouseover(function() { $(this).stop(); }) 
    .mouseout(function() { $(this).resume(); }) 

    },100); 

回答

1

下面的代碼會爲你工作的停止工作的方法,

var angle = 0; 
var int; 
rotateImage(); 

function rotateImage() { 
    int = setInterval(function() { 
     angle += 3; 
     $("#image").rotate(angle); 
    }, 50); 
} 
$("#image").mouseover(function() { 
    clearInterval(int); 
    //$(this).stop(); 
}).mouseout(function() { 
    rotateImage(); 
});​ 

http://jsfiddle.net/73pXD/2393/

+0

感謝的人是工作 你能解釋一下你做了什麼 那是什麼clearInterval – Marcos 2012-07-30 14:45:14

+0

'clearInterval'清除使用'setInterval'其設定的時間間隔。要做這個區間變量應該是全局的。 'setInterval'定期調用任何函數,'clearInterval'會停止它。 – 2012-07-31 05:09:51

+0

@Marcos:希望你知道如何表達謝意。 – 2012-07-31 10:40:49