2016-02-25 171 views
0

我做了我簡單的網站與四個按鈕。如果我點擊一個,我希望它播放聲音,當聲音播放完畢(或'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> 
+1

超時,這可能是有用的:http://stackoverflow.com/questions/9419263/playing-audio-with-javascript – Mike

+0

重定向在哪裏?做什麼? – zer00ne

回答

0

你需要嵌入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,那麼如果用戶在開始播放音頻之前在頁面上停留了幾秒鐘,則可以修復此問題,但如果這還不夠,則必須將該事件阻止到音頻已經加載或只是激發重定向 –