当前位置:网站首页>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)
边栏推荐
- Pytorch学习笔记(二)神经网络的使用
- Target detection network r-cnn series
- Implementation of SAP ABAP daemon
- 如何构建以客户为中心的产品蓝图:来自首席技术官的建议
- JSON data transfer parameters & date type parameter transfer
- AI theory knowledge map 1 Foundation
- .NET WebAPI 使用 GroupName 对 Controller 分组呈现 Swagger UI
- Leetcode 263. ugly number
- LeetCode 1523. 在区间范围内统计奇数数目
- Codeforces round 810 (Div. 2) [competition record]
猜你喜欢
![[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from](/img/f6/03e39799db36c33a58127359aa2794.png)
[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from

Algorithm -- continuous sequence (kotlin)

LCL三相pwm整流器(逆变器)
Control the probability of random winning [C | random]

Detailed explanation of factory mode

Win11+VS2019配置YOLOX

How to write the introduction of GIS method journals and papers?

历时15年、拥有5亿用户的飞信,彻底死了

Implementation of SAP ABAP daemon

Flutter multi-channel packaging operation
随机推荐
Solve the problem that the remote host cannot connect to the MySQL database
How to realize the reality of temporary graphic elements
【C语言学习者必会的题目集锦1】巩固基础,稳步提高
TDSQL-C Serverless:助力初创企业实现降本增效
解决远程主机无法连接mysql数据库的问题
Feixin, which lasted 15 years and had 500million users, was completely dead
Seven steps to copywriting script ---- document team collaborative management
Flutter multi-channel packaging operation
Golang port scanning design
Implementation of SAP ABAP daemon
Analysis on the current situation and optimization strategy of customer experience management in banking industry
Golang端口扫描设计
LCL三相pwm整流器(逆变器)
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
Probability theory and mathematical statistics
LeetCode 263.丑数
数据泄漏、删除事件频发,企业应如何构建安全防线?
Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
One stroke problem (Chinese postman problem)
With frequent data leakage and deletion events, how should enterprises build a security defense line?