Ⅰ 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度呢
現在我們以這個蘋果的圖片作為例子