文本跟随鼠标并且显示x轴和y轴位置
一、文本跟随鼠标并且显示x轴和y轴位置
代码如下:
window.onload=function(){ var mydiv = document.createElement("div"); mydiv.setAttribute("id","hint"); mydiv.style.position="absolute"; mydiv.style.lineHeight="15px"; mydiv.style.color="#3a3a3a"; mydiv.style.background="#fff"; mydiv.style.padding="5px;"; mydiv.style.fontSize="12px;"; mydiv.style.borderStyle="solid"; mydiv.style.borderColor="#000000"; mydiv.style.borderWidth="1px"; mydiv.style.height="20px"; mydiv.style.display="none"; document.body.appendChild(mydiv); document.addEventListener("mousemove",function(e){ var myhint = document.getElementById("hint"); myhint.style.display= "block"; myhint.style.left= e.clientX+"px"; myhint.style.top= e.clientY+"px"; myhint.innerHTML="x坐标:"+e.clientX+",y坐标: "+e.clientY; }); }