首页 \ 问答 \ 在HTML页面中嵌入动画SVG,暂停(无需启动动画)(Embed animated SVG in HTML page, paused (without starting animation))

在HTML页面中嵌入动画SVG,暂停(无需启动动画)(Embed animated SVG in HTML page, paused (without starting animation))

您可以将SVG文件嵌入到(X)HTML 5文档中:

<object data="anim.svg" id="svganim"/>

要么

<img src="anim.svg" alt="embedded SVG"/>

但是如果anim.svg是动画的,动画将在页面加载后立即开始播放。

如何嵌入动画SVG文件,以便动画开始暂停? 然后用户可以通过按下按钮来播放动画unpauseAnimations()在Javascript中使用unpauseAnimations()

一种不雅的方式

window.onload = function() {
    var svg_anim = document.getElementById('svganim').contentDocument.rootElement;
    svg_anim.pauseAnimations();
};

缺点:如果嵌入式SVG与父文档位于不同的安全上下文中,则不起作用。 有没有更好的办法?


You can embed an SVG file into into an (X)HTML 5 document:

<object data="anim.svg" id="svganim"/>

or

<img src="anim.svg" alt="embedded SVG"/>

But if anim.svg is animated, the animation will start playing as soon as the page loads.

How can you embed an animated SVG file such that the animation starts out paused? The user can then play the animation by pressing a button (using unpauseAnimations() in Javascript)

An inelegant way

window.onload = function() {
    var svg_anim = document.getElementById('svganim').contentDocument.rootElement;
    svg_anim.pauseAnimations();
};

Disadvantage: this doesn't work if the embedded SVG is in a different security context from the parent document. Is there a better way?


原文:
更新时间:2022-10-18 16:10

最满意答案

我认为,当用户导航时,您将数据库中的值设置为会话。 因此更新你的代码(添加一个elseif)应该可以工作

if(isset($country)){
   $_SESSION['country']=$_GET['country'];
} elseif (empty($_SESSION['country'])) {
  $_SESSION['country']=$countryz['country'];
}

I think when the user navigates away you are setting the value from DB into the session. So updating your code(adding a elseif) should work

if(isset($country)){
   $_SESSION['country']=$_GET['country'];
} elseif (empty($_SESSION['country'])) {
  $_SESSION['country']=$countryz['country'];
}

相关问答

更多
  • 简单的答案是Rx Framework不支持使用像这样的递归模式来生成observables,所以它不容易完成。 用于F#序列的Combine操作需要一些特殊处理,观察对象不提供。 Rx框架可能期望您使用Observable.Generate生成observable,然后使用LINQ查询/ F#计算生成器来处理它们。 无论如何,这里有一些想法 - 首先,您需要用Observable.Concat替换Observable.Concat 。 第一个并行运行两个观察值,第二个从第一个可观察值生成所有值,然后从第二个 ...
  • 尝试这个 在您当前的迁移更改中 def change end 至 def self.up add_column :table_name, column_name, type end 然后在此之后添加 def self.down remove_column :table_name, column_name end 第一次运行 rake db:migrate:down VERSION= version_number 现在更正self.up中的列名并运行 run rake db:migrate:u ...
  • 尝试keyup事件和+ (字符串上的concat操作符) HTML This is some text
    使用Javascript var input = document.getElementById('model'); var text = document.getElementById('coltext'); function changeTextShadow(even ...
  • 最后我做的是这样的: @Override protected void onStart() { super.onStart(); if (!locale.equals(getResources().getConfiguration().locale)) { finish(); startActivity(getIntent()); overridePendingTransition(0, 0); return; } } ...
  • 我知道我迟到了一年,但我在制表和锚定方面遇到了同样的问题。 我如何修复它是通过添加一个包含所有元素并设置Dock to Fill的面板。 然后通过仅更改容器面板的父级,它可以完美地工作。 实际上这是一个应该报告给MS的错误,但是现在这个解决方法非常有效。 编辑:您还可以通过双缓冲所有控件(包括选项卡组,选项卡页面,容器面板和容器面板内的所有元素)来更改选项卡时减少/删除轻弹。 I know I'm a year late, but I just had this same problem with tabs ...
  • 可能是这样的: expandableListView.getChildAt(groupPosition) 使用子列表上的组索引,这将导致问题。 It might be this: expandableListView.getChildAt(groupPosition) Using the group index on the child list, that will cause problems.
  • $('img').prop('src', function () { return this.src.replace('domain1','domain2'); }) jsFiddle例子 $('img').prop('src', function () { return this.src.replace('domain1','domain2'); }) jsFiddle example
  • 不幸的是,Fix-it不支持所有错误/警告。 我找了一份支持的列表,没有这么幸运。 在未来的版本中可能会添加更多内容。 它仍然是一个非常新的功能,因此Apple将会看到事情的进展,改进,适应和更新。 Unfortunately Fix-it doesn't support all errors/warnings. I've looked for a list of supported ones, with no such luck. It's likely that more will be added i ...
  • 我认为,当用户导航时,您将数据库中的值设置为会话。 因此更新你的代码(添加一个elseif)应该可以工作 if(isset($country)){ $_SESSION['country']=$_GET['country']; } elseif (empty($_SESSION['country'])) { $_SESSION['country']=$countryz['country']; } I think when the user navigates away you are settin ...
  • 嗯,没有szTeam 确实改变了。 变成无法辨认的东西,莫吉巴克。 你从“罗切达尔流浪”开始,将其从utf-16编码转换为utf-8。 这很好。 调试器不会向您显示任何可识别的内容,因为它既不知道也不关心szMsg是否以utf-8编码。 然后你出错了,你正在用CP_ACP转换那个utf-8字符串。 其中表示字符串是在默认系统代码页中编码的。 它不是,它是用utf-8编码的。 修复您的问题: WCHAR* MultiByteToWideString(const char* szSrc) { int i ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)