我有一张在事件 onload 上设置的图片:
function hideMe() {
document.getElementById("navy1").style.display = "none";
}
我还有另一个功能可以在屏幕上设置图片:
function setUpPicture() {
subRunnerOBJ = new Object();
subRunnerOBJ.topPos = 100;
subRunnerOBJ.leftPos = 0;
subRunnerOBJ.velX = 400;
subRunnerOBJ.velY = 0;
subRunnerOBJ.score = 0;
snImgObj = document.getElementById("navy1");
//此时我收到消息“Microsoft JScript 运行时错误:无法获取属性'style'的值:对象为空或未定义”
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
snImgObj.style.position = "absolute";
snImgObj.style.display = "show";
startMovePicture();
知道为什么会这样吗?
//this one will set the the pictue on the right side of the screen
function setUpPicture() {
subRunnerOBJ = new Object();
subRunnerOBJ.topPos = 100;
subRunnerOBJ.leftPos = 0;
subRunnerOBJ.velX = 400;
subRunnerOBJ.velY = 0;
subRunnerOBJ.score = 0;
//document.getElementById("navy1").style.display = "show";
snImgObj = document.getElementById("navy1");
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
snImgObj.style.position = "absolute";
snImgObj.style.display = "show";
//once we place the location of the sub , we will Call to new function that will move it
startMovePicture();
}
function startMovePicture() {
dt = 50; // in miliseconds
h = setInterval("moveObj(subRunnerOBJ)", dt);
}
function moveObj(someObj) {
counter = 0;
while (counter < 3000) {
subRunnerOBJ.leftPos = subRunnerOBJ.leftPos + subRunnerOBJ.velX * dt / 1000;
subRunnerOBJ.topPos = subRunnerOBJ.topPos + subRunnerOBJ.velY * dt / 1000;
snImgObj.style.left = subRunnerOBJ.leftPos + "px";
snImgObj.style.top = subRunnerOBJ.topPos + "px";
counter = counter + 50;
if (counter == 3000) {
stopRunning()
}
}
}
function stopRunning() {
clearInterval(h);
hideMe();
}
//this function will hide the pucture on liad , and once the loop with the Pictue Running will end
//once loading the page we will not see the Picture
function hideMe() {
document.getElementById("navy1").style.display = "none";
}
}