2010-11-26 51 views

回答

1

如果你不熟悉jQuery的,如果你不想使用它,約50KB只是一些運動增加你的頁面大小,我建議你用我的功能之一:

function smooth(x, max){ 
return Math.floor((Math.sin((x/max*Math.PI)-(Math.PI/2))+1)*max/2); 
} 

和你需要一個代碼來移動該元素,如下所示:

function process(LI){ 
    LI = LI || Config.From; 
    LI++; 
    Left = smooth(LI, Config.To) 
    Config.Element.style.left = Left + 'px' 
    if (LI < Config.To) 
    setTimeout ("process("+LI+")", 10); 
} 

Config = { 
Element: document.getElementById('El1'), 
From: 0, 
To: 400 
}; 

process(); 
+0

也可以使用「阻尼」方法,如下所示:position + =(destination - position)/ damping – 2014-07-23 04:28:58

1

試着看看jQuery庫的動畫功能正是你正在尋找,並容易實現。

jQuery是在http://jquery.com/

和動畫功能特別是在

您的代碼將是這個樣子

$('El1').animate({top: "-10px"}), 1000); 
0
$("#moveme").animate({ 
    top: "30px" 
}, 1000); 

確保有id爲一個元素=」 moveme「和css position: absolute