본문 바로가기
svg

svg nested svg : animation with viewBox

by peach1227 2024. 1. 18.
<svg width="100%" height="100%" viewBox="0 0 200 200" preserveAspectRatio="xMinYMin meet" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

  <title>nested svg</title>
  <desc>we love nested svgs!
this is fun.
preserve Aspect Ratio</desc>
  <defs>
    <symbol id="symbol1">
      <circle cx="25" cy="25" r="25" style="stroke: inherit; fill: inherit;fill-opacity:.3"></circle>
    </symbol>
  </defs>
  <rect x="0" y="0" width="25vw" height="25vh" style="stroke: blue;fill: none;"></rect>
  <svg x="0" y="0" width="25vw" height="25vh" viewBox="0 0 50 50" preserveAspectRatio="xMinYMin meet">
    <use fill="green" xlink:href="#symbol1"></use>
  </svg>
  <svg x="0" y="0" width="25vw" height="25vh" viewBox="0 0 50 50" preserveAspectRatio="xMidYMid meet" >


      <use fill="red" xlink:href="#symbol1"></use>
<animate attributeName="viewBox" values="0 0 0 0;-250 -250 500 500" begin="0" dur="3s" additive="sum" fill="freeze" repeatCount="indefinite"></animate>

  </svg>
  <svg x="0" y="0" width="25vw" height="25vh" viewBox="0 0 50 50" preserveAspectRatio="xMaxYMax meet">
    <use fill="blue" xlink:href="#symbol1"></use>
  </svg>
</svg>
nested svg we love nested svgs! this is fun. preserve Aspect Ratio
반응형