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

move an image, display value and saves current value

本文关键字:保存 移动 显示 图像      更新时间:2023-09-26

我怎样才能得到它移动多长时间的值并保存它。 所以每次有人点击它时,它只是加起来

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;
如果您希望在

有人单击 #myImage 时执行 move 函数,请使用事件处理程序。您可以使用高级模型或仅使用传统模型,因为您将其用于加载。

imgObj.onclick = moveRight; // do not execute
相关文章: