播放音频时点击按钮和声音播放完成后重定向
问题描述:
我做了我简单的网站与四个按钮。如果我点击一个,我希望它播放声音,当声音播放完毕(或'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>
答
你需要嵌入HTML音频元素:http://www.w3schools.com/tags/ref_av_dom.asp
随着该事件侦听方法播放(),因为这页描述就可以启动音频,在音频播放结束: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);`
+0
只需将音频元素属性“预加载”设置为true,那么如果用户在开始播放音频之前在页面上停留了几秒钟,则可以修复此问题,但如果这还不够,则必须将该事件阻止到音频已经加载或只是激发重定向 –
超时,这可能是有用的:http://*.com/questions/9419263/playing-audio-with-javascript – Mike
重定向在哪里?做什么? – zer00ne