html - 在不影响路径的情况下缩放 SVG

标签 html css animation svg gsap

我正在寻找一些关于在不影响内部路径的情况下缩放 SVG 容器的指示。我正在使用 Greensock.js 并希望 SVG 容器随字母本身的宽度缩放(不改变内部路径的纵横比)。最终目标是周围的字母与缩放字母一起洗牌。有关预期结果,请参见附加的 gif。

Scaling Letters Codepen Final_Result

请参阅 Codepen,但这是我设置 HTML 的方式:

<div class="letters">
    <svg class="lcontainer" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 324 406">
        <rect class="bottom" x="46" y="353" width="278" height="53" />
        <rect width="53" height="406" />
    </svg>
    <svg class="econtainer" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 324 406">
        <rect class="outer" x="46" width="278" height="53" />
        <rect class="inner" x="46" y="247" width="240" height="53" />
        <rect class="outer" x="46" y="353" width="278" height="53" />
        <rect width="54" height="406" />
    </svg>
</div>

最佳答案

感谢您的回复,正如 enxaneta 所建议的那样,我最终将所有路径放在一个 SVG 中并在其中使用它们。

我的最终答案是将它们分组,这样我就可以在字母的各个部分及其容器上使用 EventListeners,同时将它们保持在同一个 viewBox 中。

这是我的解决方案代码笔: https://codepen.io/leecranny/full/MLdBra

<div class="leah">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 982 408" height="400">
    <g class="hbox">
        <rect  x="797.125" width="53.55" height="408" />
        <rect id="h_middle" x="806.05" y="104.55" width="158.1" height="53.55" />
        <rect id="h_side" x="928.45" width="53.55" height="408" />
    </g>
    <g class="abox">
        <path id="a_short" d="M750.75169,405.5H698.34861V106.05385c0-29.082-18.01843-53.65077-39.34861-53.65077s-39.34861,24.56881-39.34861,53.65077V405.5H567.24831V106.05385C567.24831,47.57558,608.40754,0,659,0s91.75169,47.57558,91.75169,106.05385Z" transform="translate(0 1)"/>
        <path id="a_wide" d="M821.75169,405.5H769.34861V146.05385C769.34861,87,716,52.40308,659,52.40308S549.65139,91,549.65139,146.05385V405.5H497.24831V136.05385C497.24831,61,568,0,659,0S821.75169,55,821.75169,136.05385Z" transform="translate(0 1)"/>
        <rect id="a_middle" x="590.37692" y="299.5908" width="137.24615" height="52.40308"/>
    </g>
    <g class="ebox">
        <rect id="e_inner" x="243.03125" y="248" width="240" height="53" />
        <rect id="e_outer" x="243.03125" y="354" width="278" height="53" />
        <rect id="e_outer" x="243.03125" y="1" width="278" height="53" />
        <rect id="e_left" x="197.03125" y="1" width="54" height="406" />
    </g>
    <g class="lbox">
        <rect id="l_short" x="46" y="354" width="105" height="53" />
        <rect id="l_left" y="1" width="54" height="406" />
    </g>
</svg>

关于html - 在不影响路径的情况下缩放 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54830896/

相关文章:

javascript - 如何在 JavaScript 中复制 const 数组

jquery - 如何在输入文本时实现标签的即时隐藏()

html - 移动菜单按钮不在导航内

android - 制作动态壁纸

jquery - 如何使用 jQuery 使 "flat image"像弹出书一样站立

html - 电子邮件模板 Outlook

html - :hover table rows don't revert to their pre-:hover state 的属性

css - 仅影响 parent

html - 树形表jsp自定义标签

java - 动画完成后执行语句