導航:首頁 > 編程語言 > javascript獲取rotate

javascript獲取rotate

發布時間:2025-10-05 07:44:59

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度呢

現在我們以這個蘋果的圖片作為例子

閱讀全文

與javascript獲取rotate相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接