【发布时间】:2012-03-12 23:13:48
【问题描述】:
我正在尝试将图像从右向左移动
但是代码只能从左到右运行
这是一个从左到右的例子
<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
标签: javascript image move