Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Javascript获取转换?_Javascript_Jquery_Html_Transform - Fatal编程技术网

如何使用Javascript获取转换?

如何使用Javascript获取转换?,javascript,jquery,html,transform,Javascript,Jquery,Html,Transform,我想使用Javascript获取下面的“转换”数据 <svg id="svgHarita" width="5025px" height="2159px" viewBox="0 0 5025 2159" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="transform: scale(3) translate(45.5px, 122px);"&

我想使用Javascript获取下面的“转换”数据

<svg id="svgHarita" width="5025px" height="2159px" viewBox="0 0 5025 2159" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="transform: scale(3) translate(45.5px, 122px);">

  • 变量x//输出:刻度(3)
  • 变量y//输出:45.5px
  • var z//输出:122px
谢谢,
关于

您可以简单地使用
样式添加。转换

document.getElementById("svgHarita").style.WebkitTransform = "scale(3) translate(45.5px, 122px)"; 
document.getElementById("svgHarita").style.msTransform = "scale(3) translate(45.5px, 122px)"; 
document.getElementById("svgHarita").style.transform = "scale(3) translate(45.5px, 122px)";

只需使用
style.transform

document.getElementById("svgHarita").style.WebkitTransform = "scale(3) translate(45.5px, 122px)"; 
document.getElementById("svgHarita").style.msTransform = "scale(3) translate(45.5px, 122px)"; 
document.getElementById("svgHarita").style.transform = "scale(3) translate(45.5px, 122px)";

getAttribute和Regex

var regex=/scale\(\d)\.*?translate\(.*),(.*))/
console.log(
document.getElementById(“svgHarita”).getAttribute(“style”).match(regex)
);  

getAttribute和Regex

var regex=/scale\(\d)\.*?translate\(.*),(.*))/
console.log(
document.getElementById(“svgHarita”).getAttribute(“style”).match(regex)
);  

它使用的是js,使用一些更好的regExp会更好,但它完成了它的工作

let el=document.querySelector(“#svgHarita”)
设arr=el.style.transform.replace(/[\(\)translatescale,px]/gi,“”)。replace(/+//gi,“”)。trim().split(“”)
设x=arr[0]
设y=arr[1]
设z=arr[2]
console.log(x,y,z)

它使用的是js,使用一些更好的regExp会更好,但它完成了它的工作

let el=document.querySelector(“#svgHarita”)
设arr=el.style.transform.replace(/[\(\)translatescale,px]/gi,“”)。replace(/+//gi,“”)。trim().split(“”)
设x=arr[0]
设y=arr[1]
设z=arr[2]
console.log(x,y,z)

请访问,查看和。做一些研究,搜索相关话题等;如果您遇到困难,请发布您的尝试,并记录输入和预期输出。请访问,查看和。做一些研究,搜索相关话题等;如果您陷入困境,请发布您的尝试,注意输入和预期输出。我不认为这是askedI的想法,他/她想使用cssI转换svg,他/她想他想获得缩放和平移键的值,但我不认为这是askedI的想法,他/她想使用cssI将svg转换为scale和TRANSLESESKEY的值。它将删除所有文本,然后留下数字和句点,替换为“”,然后我们将“”s p a c e d”文本替换为“间隔”文本,最后使用“作为splitterYes,使用精心编制的正则表达式确实更简单:)-您还丢失了PXI。它删除了所有文本,然后留下数字和句点,替换为“”,然后我们将“”s p a c e d”文本替换为“间隔”文本,最后我们使用“作为splitterYes,使用精心编制的正则表达式的确更简单:)-而且您还丢失了px