2012-06-20 66 views
0

即時嘗試使用DHTML爲了使動畫3-5秒(從左到右的開始)。DHTML - 顯示圖片的時間有限

任何想法如何做tthat ???

//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"; 
} 

使用此功能,我可以看到的畫面不到一秒鐘......我 如何能在此處設置的時間?

回答

0

將毫秒數值替換爲等於所需秒數的數字,該數字在5秒內爲5000。刪除moveObj中的while循環,並將其替換爲clearInterval(h)hide1.style.visibility = "hidden";作爲該塊內的最後一條語句。