暂停外部 SVG 动画 [英] Pause an external SVG animation

查看:25
本文介绍了暂停外部 SVG 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用 document.getElementById("mysvg") 暂停 SVG.pauseAnimations().然而,这似乎只适用于内联 SVG.

You can pause an SVG using document.getElementById("mysvg").pauseAnimations(). However that only seems to work for inline SVGs.

有没有办法暂停使用 <img src="my.svg"/> 包含的 SVG 动画?

Is there any way to pause an SVG animation that is included using <img src="my.svg"/>?

推荐答案

正如 Paul LeBeau 所说,你不能用图像来做到这一点.你可以做到——显然——使用,就像这样:

So as Paul LeBeau said you can't do it with an image. You can do it - apparently - using <object>, something like this:

<object id="mysvg" type="image/svg+xml" data="myfile.svg"/>

然后通过:

mysvg.contentDocument

这受到 CORS 政策的限制,不幸的是,这意味着它在通过 file:// 协议访问文件时不起作用.就我而言(Doxygen),我需要它,所以我放弃了使用 Doxygen 本身的内联 SVG,如下所示:

That is restricted by the CORS policy which unfortunately means it doesn't work when accessing files via the file:// protocol. In my case (Doxygen) I needed that so I just gave up an included the SVG inline using Doxygen itself like this:

\htmlinclude "myfile.svg"

这篇关于暂停外部 SVG 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆