我試圖從右側移到一個img左的Javascript搬東西
但是代碼只從左至右
這部作品是左到右一個這一個工程
爲例<script language="javascript">
var x = 310; //Starting Location - left
var dest_x = 300; //Ending Location - left
var interval = 2; //Move 10px every initialization
function moveImage() {
//Keep on moving the image till the target is achieved
if(x<dest_x) x = x + interval;
//Move the image to the new location
document.getElementById("ufo").style.left = x+'px';
if ((x+interval < dest_x)) {
//Keep on calling this function every 100 microsecond
// till the target location is reached
window.setTimeout('moveImage()',10);
}
有人知道這個問題嗎?真的很感激它!
嘗試使間隔爲負值,或將其從x中不加入。你現在開始在310和每個循環加2,所以你不會下降到300 – Dampsquid 2012-03-12 23:21:17