導航:首頁 > 編程語言 > 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相關的資料

熱點內容
加工中心圓錐體宏程序怎麼編程 瀏覽:300
資料庫建表類型 瀏覽:746
蘋果手機數據佔用空間 瀏覽:516
電腦發文件到微信 瀏覽:252
小米手機app掉線怎麼回事 瀏覽:749
蘋果itunes恢復613 瀏覽:992
javascript獲取rotate 瀏覽:206
編程接單賺錢需要什麼水平 瀏覽:155
applogo設計教程 瀏覽:307
怎麼樣把自己錄歌的文件和視頻合起來 瀏覽:118
jsp計時器 瀏覽:489
韓服升級90b 瀏覽:53
手機數據線價格多少錢 瀏覽:933
vbnet建立cs文件 瀏覽:677
手機看書用哪個app 瀏覽:410
共享文件密碼是什麼 瀏覽:544
什麼app可以免費看芸汐傳 瀏覽:23
nw705p密碼 瀏覽:113
androidapp反編譯成工程文件 瀏覽:196
linux設備驅動程序開發 瀏覽:812

友情鏈接