<script>
var mx=0;
var my=0;
var circleX=100;//标记X轴圆心
var circleY=100;//标记Y轴圆心
function rotateImage()
{
for(var i=0;i<1;i++)
{
var d=document.getElementById('imgRotate');
document.body.appendChild(d);
with(d.style)
{
position="absolute";
};
var lx=window.event.clientX;
var ly=window.event.clientY;
var deg=Math.atan2(ly-circleX,lx-circleY);
setDeg(d,deg);
}
};
function setDeg(e,deg)
{
if(e.filters)
{
e.fw=e.fw||e.offsetWidth/2,e.fh=e.fh||e.offsetHeight/2;
var f = "DXImageTransform.Microsoft.Matrix";
if(!e.filters[f])e.style.filter+="progid:"+f+"(sizingmethod='auto expand')";
var rd=deg,pc=Math.cos(rd),ps=Math.sin(rd);
with(e.filters[f])M11=pc,M12=-ps,M21=ps,M22=pc;
var adr=(90-deg%90)*Math.PI/180,adp=Math.sin(adr)+Math.cos(adr);
with(e.style)marginTop=e.fh-adp*e.fh+"px",marginLeft=e.fw-adp*e.fw+"px";
}
else e.style.MozTransform="rotate("+deg+"deg)";
};
document.onmousemove=rotateImage;
</script>
<canvas id="canvas" width="800" height="600">
<img id="imgRotate" src="123.png" />
</canvas>
我使用了楼上的函数,可是旋转起来一直跳动,我的图片是200*200的