2012-05-10 53 views
0

我對jQuery有點新,我在這個實例中設置隊列時遇到了麻煩。jquery無限隊列

我想這樣做:在鼠標懸停時,第一個隊列條目被觸發。然後它等待,直到另一個鼠標懸停來觸發下一個隊列條目。無限循環隊列。

http://jsfiddle.net/fChDX/

$("#header").mouseover(function() { 
    var $shineCopy = $("#shine111").clone(); 
    $shineCopy.appendTo('body').animate({ 
     width: "300px", 
     height: "300px", 
     opacity: 0, 
     "left": 0, 
     "top": 100 
    }, 1000, function() { 
     $(this).remove(); 
    }); 
    $shineCopy.appendTo('body').rotate({animateTo:180}) 
}); 
​ 
$("#header").mouseover(function() { 
    var $shineCopy = $("#shine222").clone(); 
    $shineCopy.appendTo('body').animate({ 
     width: "300px", 
     height: "300px", 
     opacity: 0, 
     "left": 0, 
     "top": 200 
    }, 1000, function() { 
     $(this).remove(); 
    }); 
    $shineCopy.appendTo('body').rotate({animateTo:180}) 
}); 

$("#header").mouseover(function() { 
    var $shineCopy = $("#shine222").clone(); 
    $shineCopy.appendTo('body').animate({ 
     width: "300px", 
     height: "300px", 
     opacity: 0, 
     "left": 0, 
     "top": 300 
    }, 1000, function() { 
     $(this).remove(); 
    }); 
    $shineCopy.appendTo('body').rotate({animateTo:180}) 
}); 
+3

你能說清楚你需要什麼幫助嗎? – iambriansreed

+1

你只是綁定了三個事件處理程序,它們都將被同時執行......如果你想改變連續事件的行爲,你可能想看看我寫的這個插件:https:// github .com/fkling/jQuery-Function-Toggle-Plugin –

+0

費利克斯,這是如此的優雅和美麗。謝謝! – nuclearsugar

回答

0

已分別定義了三個功能,必須在頁面級別定義的JavaScript計數器變量,和你的鼠標懸停事件都更新coutner變量,並決定哪些功能基於它來調用。如果你想確保在前一個運行時不會觸發下一個,那麼在啓動函數中設置第二個「isrunning」變量爲true,在remove函數中設置爲false,並檢查該變量。沒有什麼奇特的要求。