Can an SVG contain audio using javascript?

前端 未结 2 1936
时光说笑
时光说笑 2021-02-15 02:34

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

To clarify:

  • This is for an SVG that
2条回答
  •  孤街浪徒
    2021-02-15 03:06

    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).

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

提交回复
热议问题