angular - 如何在 Angular8 中的 svg 动画标签上调用 beginElement()
问题描述
我在 svg 上有一个动画标签,它的“开始”设置为 begin="indefinite",这样动画就不会自动播放。我想从 Angular 中的 typeScript 函数触发动画。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-testsvg',
templateUrl: './testsvg.component.html',
styleUrls: ['./testsvg.component.scss']
})
export class TestsvgComponent {
constructor() {}
onFadePolly() {
console.log('onFadePolly');
document.querySelector('svg-id').beginElement();
}
}
<div class="svg">
<svg xmlns="http://www.w3.org/2000/svg" width="350" height="350" viewBox="0 0 350 350">
<polygon id="poly" points="220,10 300,210 170,250 123,234" style="fill:red;fill-opacity:0;stroke:black;stroke-width:1">
<animate id="svg-id" attributeName="fill-opacity" dur="4s" from="0" to="1"
fill="freeze" begin="indefinite"/>
</polygon>
</svg>
</div>
<button (click)="onFadePolly()">Fade Me Polly</button>
解决方案
推荐阅读
- reactjs - 在组件中使用 useSelector() 的结果
- python - Python 请求 - 上传文件名中带有 UTF-8 特殊字符(如“ÄÖÜ”)的文件
- reactjs - 未处理的拒绝(TypeError):zone.filter 不是函数
- javascript - React 中兄弟姐妹的访问列表
- python - Python Pandas:在将数据框保存为 csv 之前创建文件名
- azure - 在 KQL 中按属性聚合数据
- javascript - 有没有办法在单页应用程序中为不同的 URL 设置不同的 Google Tag Manager ID?
- shell - xargs 参数未解释
- c++ - 如何在不同设备之间共享 EGLImageKHR 对象
- php - 引导模式没有获取用户 ID