鼠标随移动的方向而改变
<html xmlns:v="urn:schemas-microsoft-com:vml"> <STYLE> body{margin:0px;cursor:url(http://www.jscode.cn/jscode/images/Select.cur)} v\:* { Behavior: url(#default#VML) } </STYLE>
<script> var trace="" var vP var r=0 var vS var p=new Object() var lineColor=[[255,0,0],[255,0,255]] p.x=0;p.y=0 function init(){ document.body.onmousedown=function(){ if (event.button==1 || event.button==4){ if (event.button==1) vP=document.createElement("v:PolyLine"); else vP=document.createElement("v:line"); } vS=document.createElement("v:stroke") vP.filled="false" vP.appendChild(vS) document.body.appendChild(vP) trace=""; if (event.button==4) vP.from.value=event.clientX + "," + event.clientY; } document.body.onmousemove=function(){ if (event.button==1){ pos=event.clientX + "," + event.clientY + " "; trace+=pos vS.color="rgb(255,0,0)" vP.points.value=trace } if (event.button==4) { vP.to.value=event.clientX + "," + event.clientY; } rImg.style.left=event.clientX-20; rImg.style.top=event.clientY-20; var cX = p.x-event.clientX; var cY = p.y-event.clientY; if (cX || cY) { status ="cX:"+cX+" -cY:"+cY rotationImg(180-parseInt(Math.atan2(cY,cX)*180/Math.PI,10)); } p.x=event.clientX; p.y=event.clientY; } document.body.onmouseup=function(){ vS.EndArrow="Block" } document.onselectstart=function(){return false} } function rotationImg(flag){ window.status=r + " to " + flag; var step=3; while(r-flag>180) flag+=360 while(flag-r>180) flag-=360 r += (flag-r)/step rImg.style.rotation=90-r; } </script> <body onload="init()"> <v:image id="rImg" src="http://www.jscode.cn/jscode/images/mouse.gif" style="position:absolute;top:0;left:0;width:37;height:37;0" > <v:Stroke dashstyle="Solid"/> </v:image> </body>
检测代码效果 请进
|