javascript - 当它们具有不同的变换时,有没有办法从一个 SVG 的坐标转换到另一个
问题描述
我有一个 div,其中包含两个 SVG,一个在另一个之上显示:
<div class="container" id="container">
<svg class="one" id="one" height="6000" width="6000">
...
</svg>
<svg class="two" id="two" height="6000" width="6000">
...
</svg>
</div>
使用 CSS:
.container {
perspective: 2600px;
width: 6000px;
overflow: hidden;
margin-top: -4000px;
display: grid;
}
.container .one {
transform: rotateX(120deg);
margin-bottom: -200px;
transform-origin: bottom;
grid-area: 1 / 1;
z-index: 0;
}
.container .two {
margin-bottom: -200px;
transform-origin: bottom;
grid-area: 1 / 1;
z-index: 1;
}
有没有办法在“一”尺度上获取坐标并将它们转换为“二”尺度?
我试图创建一个 SVG 点并将其 x/y 设置为“一”坐标,然后转到屏幕坐标,然后通过返回到“二”坐标
let point = one.createSVGPoint();
point.x = 3000;
point.y = 5268;
// SVGToScreen
point = point.matrixTransform(one.getScreenCTM());
// ScreenToSVG
point = point.matrixTransform(two.getScreenCTM().inverse());
但是当添加到“二”时,结果点未绘制在正确的位置。
解决方案
推荐阅读
- java - JSON解析错误后的Spring Boot人类可读错误消息
- python - ImportError:使用 certbot 时无法导入名称 UnrewindableBodyError
- file - 在grails中上传文件创建的文件的路径格式是什么
- python - 这段代码的作用和含义是什么?
- javascript - 当另一个选择时,模块化 HTML JS 按钮不关闭菜单
- authentication - 使用表单身份验证不打开匿名用户无需登录即可查看的页面
- ios - 密码屏幕作为登录确认,Swift
- postgresql - 由于 Postgresql 9.5 中的运算符优先级更改而改变其含义的条件有哪些示例?
- python - 你如何在 python 列表中分离配对值?
- python - web3钱包不接受系绳币