Javascript 如何复制函数以便我可以使用;这";在onLoad函数中。也就是这个,上装?
加载对象时,我希望它在页面上移动。运动不是最难的部分。我使用这段代码(或多或少)来实现这一点Javascript 如何复制函数以便我可以使用;这";在onLoad函数中。也就是这个,上装?,javascript,events,this,onload,self,Javascript,Events,This,Onload,Self,加载对象时,我希望它在页面上移动。运动不是最难的部分。我使用这段代码(或多或少)来实现这一点 var x = 5; //Starting Location - left var y = 5; //Starting Location - top var dest_x = 300; //Ending Location - left var dest_y = 300; //Ending Location - top var interval = 10; //Move 10px every init
var x = 5; //Starting Location - left
var y = 5; //Starting Location - top
var dest_x = 300; //Ending Location - left
var dest_y = 300; //Ending Location - top
var interval = 10; //Move 10px every initialization
function moveImage() {
//Keep on moving the image till the target is achieved
if(x<dest_x) x = x + interval;
if(y<dest_y) y = y + interval;
//Move the image to the new location
document.getElementById("ufo").style.top = y+'px';
document.getElementById("ufo").style.left = x+'px';
if ((x+interval < dest_x) && (y+interval < dest_y)) {
//Keep on calling this function every 100 microsecond
// till the target location is reached
window.setTimeout('moveImage()',100);
}
var x=5//起始位置-左侧
变量y=5//起始位置-顶部
var dest_x=300//结束位置-左侧
var dest_y=300//结束位置-顶部
var区间=10//每次初始化移动10px
函数moveImage(){
//继续移动图像直到达到目标
如果(x这样写:
var image = document.createElement('img');
image.onload = moveImage;
image.src = 'test.jpg';
然后moveImage()
中的这个将是您加载的imgp.S.窗口。setTimeout('moveImage()',100);
应该是setTimeout(moveImage,100);
。将字符串传递到setTimeout
eval
在全局范围内。