SVG可以使用javascript包含音频吗? [英] Can an SVG contain audio using javascript?

查看:269
本文介绍了SVG可以使用javascript包含音频吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的javascript互动的SVG,我也希望能够将一些音频放入其中。

I have an SVG with some basic javascript interactivity, and I would love to be able to put some audio into it as well.

澄清:


  • 这是针对SVG本身,而不是HTML内联

  • 我宁愿避免使用javascript库,但我可以,如果有必要。

有关如何实现这一点的任何见解?

Any insight on how this could be accomplished?

推荐答案

如果您需要支持HTML5音频的浏览器,那么可以将音频元素放在svg中(使用XHTML命名空间音频元素及其子代)。上次我尝试它不需要foreignObject包装器。 这是一个示例,展示了如何做到这一点(适用于chrome,firefox和opera)。

If you require a browser with support for HTML5 audio, then it's possible to just put the audio elements in the svg (use the XHTML namespace for the audio element and its children). Last time I tried it didn't require a foreignObject wrapper. Here's an example showing how to do that (works in chrome, firefox and opera).

也可以使用javascript创建HTML5音频元素并在SVG中使用它们。

It's also possible to create HTML5 audio elements with javascript and use them inside the SVG.

这篇关于SVG可以使用javascript包含音频吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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