移动图像,显示值并保存当前值

时间:2012-06-21 17:03:26

标签: javascript image get

我怎样才能获得它移动并保存多久的价值。因此,每当有人点击它时,它就会加起来

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;

1 个答案:

答案 0 :(得分:0)

如果您希望在有人点击#myImage时执行移动功能,请使用event handler。您可以使用advanced modeltraditional,因为您已将其用于onload。

imgObj.onclick = moveRight; // do not execute