简体   繁体   English

SVG动画由Aurelia控制

[英]SVG animation controlling by Aurelia

I have a problem with an animation controlled with Aurelia. 我使用Aurelia控制的动画有问题。

app.html app.html

<path
   style="fill:none;stroke:#000000;stroke-width:3"
   d="M 1.6443859,34.308976 C 0.37273852,24.831561 7.0248286,16.117725 16.502244,14.846077 25.979658,13.574431 34.693495,20.226519 35.965142,29.703934 37.236789,39.181349 30.5847,47.895186 21.107285,49.166833 15.541877,49.913581 10.23978,47.927929 6.5533998,44.242297"
>

 <animateTransform 
   attributeName="transform" attributeType="XML" type="rotate" from.bind="fromCW" 
   to.bind="toCW" dur.bind="duration" fill="freeze"
 />
</path>

<button repeat.for="state of states" click.trigger="changeState({state})">${state}</button>

app.ts app.ts

states = ["opening", "closing"];
duration:string = "10s";
rotationPoint: string = " 18.9 32.05";
rightRotation = -95 + this.rotationPoint;
leftRotation= 130 + this.rotationPoint;
zero = 0 + this.rotationPoint;
state:string;
fromCW:string;
fromCCW:string;
toCW:string; 
toCCW:string;

domeAnimate(): void{
  switch (this.state){
    case "opening":
      this.fromCW = this.fromCCW = this.zero;
      this.toCW= this.leftRotation;
      this.toCCW = this.rightRotation;
      break;
    case "closing":
      this.fromCW = this.leftRotation;
      this.fromCCW = this.rightRotation;
      this.toCW = this.toCCW = this.zero;
      break;
  }
}
changeState(id):void {
  this.state = id.state;
  this.domeAnimate();
}

Here is how does it look like 这是什么样子

Right now the animation starts when the button is clicked. 现在,单击按钮时动画开始。 ie: when I click the "Opening" button the opening animation starts, then switch to "Closing" and the closing animation is in the middle. 即:当我单击“开始”按钮时,开始动画开始,然后切换到“关闭”,结束动画在中间。 When the animation is done I am not able to run it again. 动画制作完成后,我将无法再次运行它。

What I'd like to do it here is to start the proper animation (opening or closing) when I click the button connected to it everytime I click it. 我想在这里做的是,每当我单击连接到它的按钮时,就开始播放适当的动画(打开或关闭)。

I don't want to use SVG.beginElement() here. 我不想在这里使用SVG.beginElement()

Thanks 谢谢

The issue you got is because SVG animation via <animateTransform/> by default is run only once. 您遇到的问题是因为默认情况下,通过<animateTransform/>的SVG动画仅运行一次。 Try adding an attribute repeatCount="indefinite" , it will work as expected. 尝试添加一个属性repeatCount="indefinite" ,它将按预期工作。

Here is a link to a working version https://stackblitz.com/edit/aurelia-javascript-p77wvh?file=src%2Fapp.js 这是工作版本的链接https://stackblitz.com/edit/aurelia-javascript-p77wvh?file=src%2Fapp.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM