0

我尝试使用 DHTML 来制作 3-5 秒的动画(动画假设从左到右开始......)。

知道该怎么做吗???

//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;
    hide1.style.visibility = "visible";
    hide1.style.left = subRunnerOBJ.leftPos + "px";
    hide1.style.top = subRunnerOBJ.topPos + "px";
    hide1.style.position = "absolute";
    //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 < 30000) {
        subRunnerOBJ.leftPos = subRunnerOBJ.leftPos + subRunnerOBJ.velX * dt / 1000;
        subRunnerOBJ.topPos = subRunnerOBJ.topPos + subRunnerOBJ.velY * dt / 1000;
        hide1.style.left = subRunnerOBJ.leftPos + "px";
        hide1.style.top = subRunnerOBJ.topPos + "px";
        counter = counter + 50;
        if (counter == 3000) {
            stopRunning();
        }
    }
}

function stopRunning() {
    clearInterval(h);
    hide1.style.visibility = "hidden";
}

使用此功能,我可以在不到一秒的时间内看到图片……我如何在这里设置时间?

4

1 回答 1

0

将毫秒值替换为等于所需秒数的数字,即 5000 持续 5 秒。删除内部的while循环并通过添加和 moveObj替换它作为该块内的最后一条语句。clearInterval(h)hide1.style.visibility = "hidden";

于 2012-09-10T23:03:30.783 回答