2012-03-03 31 views
0

我有一些降落傘的動畫,我想添加一些隨機。每次它循環(使用jQuery的定時器插件),我想基本上它從一個隨機的左側位置運行。每當這個動畫循環創建一個隨機的「左」位置

我可以創建隨機數用下面的函數

function randomLeft() { 
var randomNumber = Math.floor(Math.random() * 101); 
return randomNumber+'%'; 
} 

我有我的循環:

$('#parachute_wrap img').everyTime (11, function(){ 
      $('#parachute_wrap img') 
      .animate({top:"1000px"},25000) 
      .animate({top:"-100px"}); 
}); 

我試着做以下幾點:

$('#parachute_wrap img').everyTime (11, function(){ 
      $('#parachute_wrap img') 
      .animate({top:"1000px"},25000) 
      .animate({top:"-100px", left: randomLeft()}); 
}); 

但它看起來就像它不喜歡當我只是拋出一個函數作爲一個值。

你會怎麼做呢?

+0

與你的語法[對我的作品(http://jsfiddle.net/didierg/jRmUc/)。你確定它不是函數.everyTime()打破了代碼? – 2012-03-03 09:46:41

+0

每次都有可能破壞代碼。 – willdanceforfun 2012-03-03 09:54:03

回答

0

你有沒有嘗試過這樣的: -

$('#parachute_wrap img').everyTime (11, function(){ 
      $('#parachute_wrap img') 
      .animate({top:"1000px"},25000) 
      .animate({top:"-100px", left: Math.floor(Math.random() * 101) + '%'}); 
}); 

OR

$('#parachute_wrap img').everyTime (11, function(){ 
      $('#parachute_wrap img') 
      .animate({top:"1000px"},25000) 
      .animate({top:"-100px", left: Math.floor(Math.random() * 101) + 'px'}); 
}); 
+0

爲什麼我會這麼做......對我來說太簡單了,因爲我的過度複雜的想法:(omg。it worked。ahhh ... thank you !!!! – willdanceforfun 2012-03-03 09:50:08