【发布时间】:2018-10-14 11:35:16
【问题描述】:
如果你看下面的 sn-p,我想在 svg 图像上实现缩放。
我希望它能够优雅地放大和缩小。
我正在使用矩阵函数,我知道我可以通过更改第一个和第四个或矩阵或a 和d 来缩减。
我将以编程方式更改变换矩阵,但我希望将 svg 保持在中心,并且在放大和缩小时不让它向左上角或右下角移动。
矩阵的最后 2 个元素或 dx 和 dy 的数学运算是什么,以使我的矩阵在缩放时保持居中?
<svg width="500" height="150">
<rect x="20" y="20" width="50" height="50" transform="matrix(.5,0,0,.5,0,0)" style="fill: #cc3333"></rect>
<rect x="20" y="20" width="50" height="50" transform="matrix(1,0,0,1,0,0)" style="fill: #cc3333"></rect>
<rect x="20" y="20" width="50" height="50" transform="matrix(1.5,0,0,1.5,0,0)" style="fill: #cc3333"></rect>
</svg>
【问题讨论】:
标签: javascript svg