【问题标题】:Playing sounds on clicking within image - upgrading to html5?在图像内单击时播放声音 - 升级到 html5?
【发布时间】:2013-04-30 20:23:29
【问题描述】:

抱歉 - 我可能对这个网站的级别太低了。我的 wordpress 帖子有时会显示在不同位置单击会播放不同声音的图像。我当前的方法(从搜索中蚕食了一段时间)如下所示。现在我发现它们不能在 iPad 等设备上播放,所以我需要 html5。我尝试在线遵循各种方法但无法使它们起作用,或者我只是不理解解决方案,例如这个Play MP3 with when an image is clicked。如果有人可以提供帮助,请尽可能明确地说明我将各种代码放在哪里,无论是在帖子中还是在 .php 文件等中。 如果我首先需要更多基本教程,也许有人可以建议?非常感谢。

我把它放在帖子的顶部

<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML="<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>
<span id="dummy">
</span>

然后在帖子内的正确位置

<img src="http://website_path/image.jpg"  width="350" height="312" usemap="#my_image" />
<map name="my_image">
<area shape="rect" coords="20,65,50,95" onclick="playSound('http://website_path/sound.mp3');"  />
</map>

【问题讨论】:

    标签: html wordpress onclick maps playsound


    【解决方案1】:

    我在 ergo 的这个自我回答中找到了解决方案: innerHTML causes unwanted scroll in Chrome

    我的第一段代码应该替换为:

    <audio id="1st_sound">
    <source src="1st_sound.ogg" type="audio/ogg" />
    <source src="1st_sound.mp3" type="audio/mpeg" />
    </audio>
    <audio id="2nd_sound">
    <source src=2nd_sound.ogg" type="audio/ogg" />
    <source src="2nd_sound.mp3" type="audio/mpeg" />
    </audio>
    

    等等

    第二位应替换为:

    <img src="http://website_path/image.jpg" width="350" height="312" usemap="#my_image" /> 
    <map name="my_image"> <area shape="rect" coords="20,65,50,95" onClick="document.getElementById('1st_sound').play(); return false;" />
    </map>
    

    等等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-03
      相关资源
      最近更新 更多