2013-07-30 74 views
0

我想要做的是創造,當我鼠標滾輪上/下,動畫運行的開關(但將確保在動畫第一完成之前,第二和第三...Jquery布爾開關不工作?

什麼我做的是將我的動畫變量設置爲true,並首次運行它,並立即將其切換爲false。

不知何故,條件語句似乎並不奏效.....

我的示例代碼: http://codepen.io/vincentccw/pen/veyAc

//////////////// ////////////////

$("#cropInside").mousewheel(function(event, delta, deltaX, deltaY) { 

var boxSlide = document.getElementById("whatEver"); 
var animationStatus = true; 

if ([delta > 0] && [animationStatus==true]){ 
    //code here 
    animationStatus=false; 
    console.log(animationStatus); 
    //call back function after animation complete and set animationStatus=true; 
} 

if([delta < 0] && [animationStatus==true]){ 
    //code here 
    animationStatus=false; 
    console.log(animationStatus); 
    //call back function after animation complete and set animationStatus=true; 
} 

}); 

/////// /////////////////

+0

我注意到你有幾個沒有答案的問題和沒有被接受的答案的問題。我喜歡在他們身上工作。如果您有任何問題,請告訴我! – m59

回答

0

問題在我看來你正在包裝你的條件可以有效地做出如下陳述:

if ([true] && [true]) { 
if ([false] && [true]) { 
if ([true] && [false]) { 
if ([false] && [false]) { 

這是通過將數組轉換爲布爾值來評估的。如果您這樣做:console.log([delta > 0])日誌將顯示一個包含值truefalse的數組。將數組計算爲布爾值時,數組的內容無關緊要 - 因爲數組爲true(儘管爲空),所以將會記錄true。這不是一種很好的檢查方式,我懷疑這是你的意圖。似乎刪除您的條件array包裝時,它們工作正常:

if (delta > 0 && animationStatus==true) { 

還要注意的是,你應該避免==贊成===鬆散比較==也可能導致一些意外行爲。