2011-08-04 19 views
0

使用JQuery的jquery.animate-colors-min.js插件我試圖改變序列中某些div框的背景顏色。試圖以指定的順序更改div背景顏色

$('#firstbox').animate({ backgroundColor: "#f6f6f6" }, 'slow') 

以上是我用來製作動畫的正常工作:第一箱,但我不知道我怎麼會去啓動一個回調(如果可能的話),以動畫的下一個指定框的背景色。

下面這只是事情的例子的woulda很大,雖然預期它不工作

$('#firstbox').click(function(){ 

    $('#firstbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'), function(){ 
       $('#secondbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'); 
     }) 

任何建議將受到歡迎。

感謝

回答

0

你有一個語法錯誤:

$('#firstbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'), function(){ 
    $('#secondbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'); 
}) 

應該是:

$('#firstbox').animate({ backgroundColor: "#f6f6f6" }, 'slow', function(){ 
    $('#secondbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'); 
}) 
0

動畫()有三個參數

$('#firstbox').click(function(){ 
    $('#firstbox').animate({ backgroundColor: "#f6f6f6" }, 'slow', function(){ 
       $('#secondbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'); 
    }); 
}); 
+0

嗨,謝謝你的回答工作正常。如果我想以回調函數的方式動畫10個盒子,有沒有一種簡單的方法可以將它實現在循環函數中,而不是許多重複的代碼行?如果你明白我的意思?謝了哥們 –

1

試試這個

$('#firstbox').click(function(){ 

    $(this).animate({ backgroundColor: "#f6f6f6" }, 'slow', function(){ 
       $('#secondbox').animate({ backgroundColor: "#f6f6f6" }, 'slow'); 
     }); 
});