图片跟随鼠标的移动而移动, 当点击鼠标的时候,图片就固定在那里

<html>
<head>
       <script type="text/javascript">
       var flag=0;//0表示图片移动,1表示点击后图片不移动
       function doit(){
	if(flag==0){
	   var obj = document.getElementById("tampon");
	   obj.style.left = event.x-20;
	   obj.style.top = event.y-20;
         }
       }
       window.onload=function(){
	 document.body.onmousemove = doit;    
       }
       document.onclick = mouseClick;
       function mouseClick(e){
	  flag=1;
	  var x,y;
	  if(!document.all){
		x=e.pageX;
		y=e.pageY;
	  }else{
		x=document.body.scrollLeft+event.clientX;
		y=document.body.scrollTop+event.clientY;
	  }
		
        }
       </script>
</head>
<body style="cursor:none;">
	<img id="tampon" style="position:absolute;z-index:10;" src="censored.png"/>
</body>
</html>

你可能感兴趣的:(图片)