当前位置:网站首页>Native JS get transform value x y z and rotate rotation angle
Native JS get transform value x y z and rotate rotation angle
2022-07-26 13:41:00 【Tangce】
CSS3 In the age of, we often operate transform Animation properties , So there will also be people who want to get transform When attributes , But when you go to get the value, you are confused , What comes out is matrix Matrix value , And a little annoys you , When you have operated z, The length and sort of the matrix are different , You cannot fix the value ,( Seems to use jQ One way to get it is to get it fixed ), In order to get these values normally , I found some pure js The revision of the version is finally done .
function getTranslate(node,sty){// obtain transform value
var translates=document.defaultView.getComputedStyle(node,null).transform.substring(7);
var result = translates.match(/\(([^)]*)\)/);// Regular () Content
var matrix=result?result[1].split(','):translates.split(',');
if(sty=="x" || sty==undefined){
return matrix.length>6?parseFloat(matrix[12]):parseFloat(matrix[4]);
}else if(sty=="y"){
return matrix.length>6?parseFloat(matrix[13]):parseFloat(matrix[5]);
}else if(sty=="z"){
return matrix.length>6?parseFloat(matrix[14]):0;
}else if(sty=="rotate"){
return matrix.length>6?getRotate([parseFloat(matrix[0]),parseFloat(matrix[1]),parseFloat(matrix[4]),parseFloat(matrix[5])]):getRotate(matrix);
}
}
function getRotate(matrix){
var aa=Math.round(180*Math.asin(matrix[0])/ Math.PI);
var bb=Math.round(180*Math.acos(matrix[1])/ Math.PI);
var cc=Math.round(180*Math.asin(matrix[2])/ Math.PI);
var dd=Math.round(180*Math.acos(matrix[3])/ Math.PI);
var deg=0;
if(aa==bb||-aa==bb){
deg=dd;
}else if(-aa+bb==180){
deg=180+cc;
}else if(aa+bb==180){
deg=360-cc||360-dd;
}
return deg>=360?0:deg;
}
/* The first parameter is the element , The second is to get x y z rotate this 4 One of them
Okay , Whether you use it or not translate3d still translateX、translateY, All available x y z*/
var nowRotate=getTranslate(document.getElementById(“id”),“x”);
console.log(nowRotate)
边栏推荐
- 白帽子揭秘:互联网千亿黑产吓退马斯克
- How to realize the reality of temporary graphic elements
- Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
- 【黑马早报】字节旗下多款APP下架;三只松鼠脱氧剂泄露致孕妇误食;CBA公司向B站索赔4.06亿;马斯克否认与谷歌创始人妻子有婚外情...
- One stroke problem (Chinese postman problem)
- Photoshop(CC2020)未完
- ROS2学习(1)ROS2简述
- Codeforces Round #810 (Div. 2)【比赛记录】
- [turn] judge the relationship between two geometries in ArcGIS
- Solution 5g technology helps build smart Parks
猜你喜欢

【OAuth2】八、OAuth2登录的配置逻辑-OAuth2LoginConfigurer和OAuth2ClientConfigurer

飞盘,2022年“黑红”顶流

【Oauth2】五、OAuth2LoginAuthenticationFilter

终极套娃 2.0 | 云原生交付的封装

Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web

上一次听到易趣,还是上一次

Hcip day 12 notes sorting (BGP Federation, routing rules)

AI theory knowledge map 1 Foundation

Photoshop (cc2020) unfinished

Hcip day 11 comparison (BGP configuration and release)
随机推荐
.net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
Detailed explanation of factory mode
Leetcode 217. there are duplicate elements
异步线程池在开发中的使用
LCL three-phase PWM rectifier (inverter)
Using the geoprocessor tool
[turn] judge the relationship between two geometries in ArcGIS
(Reprint) creation methods of various points in ArcGIS Engine
Some practical operations of vector
Why does WPS refuse advertising?
We were tossed all night by a Kong performance bug
Pytorch学习笔记(三)模型的使用、修改、训练(CPU/GPU)及验证
One stroke problem (Chinese postman problem)
Team research and development from ants' foraging process (Reprint)
Solve the problem that the remote host cannot connect to the MySQL database
Thoughts on the compilation of Dr. Shuo's opening report
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Huawei computer test ~ offset realizes string encryption
JSON数据传递参数&日期型参数传递
力扣------字符串中的单词数