获取鼠标在图片坐标位置的小例子

< div  id ="mouse" > 鼠标不在图片上 </ div >
< div  id ="img"  onMouseMove ="move();"  onMouseOut ="out();"  style ="position:absolute;top:100px;left:200px;" >< img  src =""  width ="400"  height ="300" ></ div >
< script >
    
function move(){
        
var img=document.getElementById("img");
        document.getElementById(
"mouse").innerHTML=(window.event.clientX-img.offsetLeft)+":"+(window.event.clientY-img.offsetTop);
    }

    
function out(){
        document.getElementById(
"mouse").innerHTML="鼠标离开图片"
    }

</ script >
 

你可能感兴趣的:(获取鼠标在图片坐标位置的小例子)