缩放和转换后,在Snap.svg中获得新的点

Get the new points in a Snap.svg after a scale and transform

本文关键字:svg Snap 转换 缩放      更新时间:2023-09-26

我已经像这样声明了一个SVG组:

<g id="group-test">
    <polygon id="polygon-test" fill="#00ff00" points=" 249.60000610351562,90 197.50000762939453,90 171.4000072479248,45 197.4000072479248,0 249.5000057220459,0 275.6000061035156,45 275.5000061020255,45.30000001192093 249.60000610351562,90" />
    <text x="200" y="50" fill="#000000" font-size="14">Xx</text>
</g>

然后用Snap设置组选择,使用父svg作为sn,然后animate:

var back = sn.select('#group-test');
setTimeout(function ()
{
    back.animate(
    {
        transform: 's4.06 4.06 t-0.5,34.5'
    },
    1000,
    mina.linear);
},
3000);

但是当我执行alert($('#polygon-test').attr('points'));我得到的是比例尺前的原始点。我如何得到新的点?Firebug也会显示旧的

您将无法看到转换后的点,因为点本身在元素上作为属性保持未转换。

您需要将这些点传递给某个东西以返回转换后的点。Snap有这样一个功能…

Snap.path.map( path, matrix );

您可以从element.transform().localMatrix

获取矩阵

http://snapsvg.io/docs/Snap.path.map