【问题标题】:Play audio when clicking on button and redirect after sound is done playing单击按钮时播放音频并在播放完声音后重定向
【发布时间】:2016-02-25 21:07:32
【问题描述】:

我用四个按钮制作了一个简单的网站。如果我点击一个,我希望它播放声音,当声音播放完毕(或在“X”秒后)我希望它重定向。

到目前为止,这是我的代码。我不知道如何输入声音和延迟。

<html>
<head>

<link rel="stylesheet" type="text/css" href="/level1/style.css">



</head>

<body>



<img STYLE= "top: 20px; Left: 200px; height:900px; width: 800px position:      absolute;" src="\images\border.jpg">
<img STYLE= "position: absolute; top: 50px; Left: 50px; height:120px; width:  120px;" src="\images\level1.jpg">

<a href="#"><img src="\images\1a1.jpg" onmouseover="this.src='/images/1a1g.jpg'"
onmouseout="this.src='/images/1a1.jpg'"  id="a1"> </a>
<a href="\level1\index.html"><img src="\images\1a2.jpg" onmouseover="this.src='/images/1a2g.jpg'"
onmouseout="this.src='/images/1a2.jpg'" " id="a2"> </a>
<a href="\level1\index.html"><img src="\images\1a3.jpg"   onmouseover="this.src='/images/1a3g.jpg'"
onmouseout="this.src='/images/1a3.jpg'"  id="a3"> </a>
<a href="\level1\index.html"><img src="\images\1a4.jpg" onmouseover="this.src='/images/1a4g.jpg'"
onmouseout="this.src='/images/1a4.jpg'"  id="a4"> </a>






</body>

</html>

【问题讨论】:

标签: javascript html button delay


【解决方案1】:

您需要嵌入一个 HTML 音频元素:http://www.w3schools.com/tags/ref_av_dom.asp

使用事件监听器中的 play() 方法,如本页所述,当音频播放结束时,您可以启动音频:http://www.w3schools.com/tags/av_event_ended.asp 您可以设置超时

`var seconds= 3;
setTimeout(
        function(){
              /*  This code will be executed, after the defined Delay  */
              }
 seconds * 1000);`

【讨论】:

  • 只需将音频元素属性“preload”设置为true,然后这个问题就可以解决,如果用户在页面上停留几秒钟,然后开始音频,但如果这还不够,你将不得不阻止事件直到音频加载或只是触发重定向
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-16
  • 1970-01-01
  • 2012-07-07
相关资源
最近更新 更多