Ⅰ js怎样获取元素的rotate属性
<!>
<html>
<head>
<metacharset=UTF-8>
<title>recursion</title>
<styletype="text/css">
</style>
<scripttype="text/javascript">
vartest=function()
{
varreg=/(rotate([-+]?((d+)(deg))))/i;
varwt=div.style['-webkit-transform'],wts=wt.match(reg);
var$2=RegExp.$2;
console.log($2);
div.style['-webkit-transform']=wt.replace($2,parseFloat(RegExp.$3)+10+RegExp.$4);
}
</script>
</head>
<body>
<buttononclick="test();">rotate</button>
<divid="div"style="width:300px;height:300px;border:1pxsolidblack;-webkit-transform:translate(300px,0px)rotate(10deg)scale(1,1)">ddd</div>
</body>
</html>
Ⅱ javascript canvas 如何对图片进行绕中心点旋转
给你一个旋转的demo:
<!DOCTYPEhtml>
<html>
<body>
<canvasid="myCanvas"width="300"height="150"style="border:1pxsolid#d3d3d3;">
.
</canvas>
<br/>
<inputtype="text"id="angle_v"readonly="1"/>
<script>
varc=document.getElementById("myCanvas");
varctx=c.getContext("2d");
ctx.translate(100,45)
//ctx.rotate(70*Math.PI/180);
//ctx.fillRect(-50,-25,100,50);
varangle=10;
varangle_now=0;
myRotate()
functionmyRotate()
{
ctx.clearRect(-100,-50,200,100);//x2是为了把原来的图全部抹掉(不留下痕迹)
ctx.rotate(angle*Math.PI/180);
ctx.fillRect(-50,-25,100,50);
angle_now=(angle_now+angle)%360;
document.getElementById("angle_v").value="当前角度:"+angle_now;
setTimeout(myRotate,1000);
}
</script>
</body>
</html>
注意:用roate实现旋转,重点在于改变坐标中心点 :ctx.translate(100,45)
坐标中心点计算公式:x = 左上角x + 宽度/2
y = 左上角y + 高度/2
然后translate到(x,y)即可,之后调用rotate进行旋转。
旋转之后填充时注意:ctx.fillRect(-50,-25,100,50);
x = - 宽度/2
y = -高度/2
fillRect(x,y,宽度,高度)
你的例子,代码控制比较看不懂。。。,所以没在基础上整改。
补充一个参考网站(英文的):http://tutorials.jenkov.com/html5-canvas/transformation.html
(如果有帮助,望采纳,谢谢)
Ⅲ JavaScript如何实现层(或层里面内容)的旋转
<!-- 每点击一次,就旋转90度版 -->
<div>
<img style='filter:progid:DXImageTransform.Microsoft.Matrix(SizingMethod="auto expand",FilterType="bilinear",Dx=0,Dy=0)' id=w src='d:\10.jpg' width="292" height="429"></div>
<button onclick='with(w.filters.item(0)){try{P==1}catch(e){P=0}P+=90;z=Math.PI*2/360*P;m12=-Math.sin(z);m21=Math.sin(z);m11=Math.cos(z);m22=Math.cos(z)}'>每点击一次,权就旋转90度</button>
Ⅳ js 怎么实现点击一次图片旋转90度,再点击再转90度呢
现在我们以这个苹果的图片作为例子