2012-06-21 40 views
0

如何獲取移動的時間並保存它的值。所以每次有人點擊它,它只是增加了移動圖像,顯示值並保存當前值

var imgObj = null; 
function init(){ 

    imgObj = document.getElementById('myImage'); 
    imgObj.style.position= 'relative'; 
    imgObj.style.left = '0px'; 
} 
function moveRight(){ 
    if(parseInt(imgObj.style.left) < 700){ 
    imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px'; 
    } 
    if(parseInt(imgObj.style.left) == 700){ 
    imgObj.style.left = parseInt(imgObj.style.left) + 0 + 'px'; 
    } 
} 
window.onload =init; 
+0

問題不明確 –

回答

0

如果你想移動功能來執行,當有人點擊了#myImage,使用event handler。您可以使用advanced model或僅使用traditional,因爲您已將它用於onload。

imgObj.onclick = moveRight; // do not execute