Установить начало и поворот на пути animateMotion - PullRequest
0 голосов
/ 11 апреля 2019

Я бы хотел применить вращение к пути, анимированному с помощью тега SVG animateMotion. Кажется, что правило transform-origin: 50%; transform: rotate (240deg); , примененное к пути, которому следует тег animateMotion, не изменяет анимацию.

<path id="theMotionPathIdLikeToRotate" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="aqua" fill="none" style="transform-origin:50%;transform: rotate(120deg);" stroke-linecap="round" stroke-linejoin="round" />

Моя цель состояла в том, чтобы создать анимацию и повторить ее преобразованную. В этом примере Я хотел создать другие движущиеся круги, повернутые на 120 и 240 градусов вокруг центра шестиугольника.

1 Ответ

2 голосов
/ 11 апреля 2019

Используется только определение пути (d) пути, на который ссылается элемент <mpath>.Любое значение transform, которое оно может иметь, игнорируется.

Вам необходимо применить преобразование к кругу и <mpath> вместе.

    <g style="transform-origin:50%;transform: rotate(240deg);">
      <circle cx="0" cy="0" r="5" fill="#333333">
        <animateMotion dur="4.45s" repeatCount="once">
          <mpath xlink:href="#theMotionPath3"/>
        </animateMotion>
      </circle>
    </g>"

<!DOCTYPE HTML>
  <html>
    <body>
      <?xml version="1.0"?>
    <svg width="400" height="400" viewBox="0 0 200 200"
        xmlns="http://www.w3.org/2000/svg" version="1.1"
        xmlns:xlink="http://www.w3.org/1999/xlink" style="background:aquamarine">
        <style>
        path {
          animation-name:animateDash;
          animation-duration:5s;
          animation-iteration-count:once;
        }
        @keyframes animateDash {
          from{stroke-dasharray:0,2305}
          to  {stroke-dasharray:2305,0}
        }
        </style>


        <circle cx="50%" cy="50%" r="1" fill="firebrick"  />

        <path id="theMotionPath" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="antiquewhite" fill="none" stroke-linecap="round" stroke-linejoin="round" />

        <path id="theMotionPath2" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="aqua" fill="none" style="transform-origin:50%;transform: rotate(120deg);" stroke-linecap="round" stroke-linejoin="round" />
        
        <path id="theMotionPath3" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="azure" fill="none" style="transform-origin:50%;transform: rotate(240deg);" stroke-linecap="round" stroke-linejoin="round" />

        <circle cx="0" cy="0" r="5" fill="#333333">
          <animateMotion dur="4.45s" repeatCount="once">
            <mpath xlink:href="#theMotionPath3"/>
          </animateMotion>
        </circle>

        <g style="transform-origin:50%;transform: rotate(120deg);">
          <circle cx="0" cy="0" r="5" fill="#333333">
            <animateMotion dur="4.45s" repeatCount="once">
              <mpath xlink:href="#theMotionPath3"/>
            </animateMotion>
          </circle>
        </g>"

        <g style="transform-origin:50%;transform: rotate(240deg);">
          <circle cx="0" cy="0" r="5" fill="#333333">
            <animateMotion dur="4.45s" repeatCount="once">
              <mpath xlink:href="#theMotionPath3"/>
            </animateMotion>
          </circle>
        </g>"

    <!--- HIDES animateMotion's reset-->
            <circle cx="" cy="" r="20" fill="aquamarine"  />
      <script type="text/javascript">
        console.log(theMotionPath.getTotalLength());
      </script>
    </svg>
  </body>
</html>
...