Javascript

【Javascript】画像をホバーすると音が鳴るImage Hover Sound

March 16, 2017
Image-Hover-Sound

Image Hover Soundは画像上にマウスオーバーするとオーディオクリップが再生されます。

HTML

  <img src="http://placehold.it/350x150" alt="..." id="soundobj" onmouseover="playSound('mySound')" onmouseout="stopSound('mySound')">

  <audio id='mySound' src='sound.mp3'/>
  Your browser does not support the audio element. Please upgrade your browser.
  
  <script>
    function playSound(soundobj) {
        var thissound=document.getElementById(soundobj);
        thissound.play();
    } function stopSound(soundobj) {
        var thissound=document.getElementById(soundobj);
        thissound.pause();
        thissound.currentTime = 0;
    }
  </script>

Download