18910140161

JavaScript-转到新页面前触发声音-堆栈溢出

顺晟科技

2022-10-19 14:45:15

190

我有这个proyect要交付给我的学校,在那里我需要制作一个页面,我想制作一个类似游戏的投资组合,但我想让人单击一个定制按钮,在它重定向到新页面之前,它可以为它发出一个定制的声音。

    <header headerIndex>
  <audio id="selectaudio" preload="auto">
    <source  src="./audio/selectsound.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>
  <a href="./pages/welcome.html" class="rpgui-button beginButton" id="playAudio">Lets Begin!</a>
    </header>    

所以这是我的代码,没有什么特别的。在移动到名为“welcome.html”的新页面之前,我如何使它发出音频声音。

如果需要任何javascript,我可以添加它,因为我会试着理解它是做什么的哈哈。谢谢!


顺晟科技:

我想这应该会有帮助,我也是JavaScript新手

我认为在重定向到另一页之前,您需要一点时间来播放声音。

我将这样做(需要Jquery):

    <header headerIndex>
  <audio id="selectaudio" preload="auto">
    <source  src="./audio/selectsound.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>
  <a href="./pages/welcome.html" class="rpgui-button beginButton" id="playAudio">Lets Begin!</a>
    </header>    

和JS

    <header headerIndex>
  <audio id="selectaudio" preload="auto">
    <source  src="./audio/selectsound.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>
  <a href="./pages/welcome.html" class="rpgui-button beginButton" id="playAudio">Lets Begin!</a>
    </header>    

https://codepen.io/yortem/pen/gozbylb

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航