CSS transform origin issue on svg sub-element

后端 未结 1 1752
灰色年华
灰色年华 2020-12-04 04:03

I\'m having issues with the transform-origin while attempting to scale sub-elements.

While attempting to scale animate a box within a larger svg, it uses the transfo

相关标签:
1条回答
  • 2020-12-04 04:25

    You need transform-box: fill-box;

    @keyframes scaleBox {
      from {transform: scale(0);}
      to {transform: scale(1);}
      }
      #animated-box {
        transform-box: fill-box;
      	animation: scaleBox 2s infinite;
      }
    <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="
            width: 195px;
        "><defs>
        <style>.cls-1{fill:#7f7777;}.cls-2{fill:#fff;}</style>
        </defs>
        <rect class="cls-1" x="0.5" y="0.5" width="99" height="99"></rect>
        <path d="M99,1V99H1V1H99m1-1H0V100H100V0Z"></path>
        <rect id="animated-box" class="cls-2" x="10.5" y="8.5" width="22" height="6"></rect></svg>

    0 讨论(0)
提交回复
热议问题