嗨,我有一些jQuery的麻煩!如何鏈接多個jQuery動畫功能?
我有幾個按鈕,都需要啓動一個獨特的動畫效果onclick。每個按鈕都有不同的動畫!
我有一塊代碼,我使用的效果很好。 我簡單的想複製這段代碼幾次,改變一些元素和值在這裏和那裏,但我不能讓它工作!請幫忙!!??
的代碼看起來像這樣...
$('#animation2').click(function(){
setTimeout("animation()",2000);
});
function animation(){
float_boat();
sail_away();
}
function float_boat(){
$(".boat").animate({top:"-=80px"},800).animate({top:"+=100px"}, 1200);
setTimeout("float_boat()",2000);
}
function sail_away(){
$(".sailboat").animate({left:"80%",marginLeft:"0px"}, 3500).fadeTo(600, 0);
}
$('#animation3').click(function(){
setTimeout("animation()",2000);
});
function animation(){
bounce_bike();
ride_away();
}
function bounce_bike(){
$(".motorbike").animate({top:"-=80px"},800).animate({top:"+=100px"}, 1200);
setTimeout("bounce_bike()",2000);
}
function ride_away(){
$(".motorcycle").animate({left:"80%",marginLeft:"0px"}, 3500).fadeTo(600, 0);
}
$('#animation4').click(function(){
setTimeout("animation()",2000);
});
function animation(){
float_balloon();
float_away();
}
function float_balloon(){
$(".balloon").animate({top:"-=80px"},800).animate({top:"+=100px"}, 1200);
setTimeout("float_balloon()",2000);
}
function float_away(){
$(".airballoon").animate({left:"80%",marginLeft:"0px"}, 3500).fadeTo(600, 0);
}
爲什麼不只是在你的超時設置一個匿名函數,而不是調用你已經定義了多次的函數呢? – 2013-04-25 15:54:20