需要帮助使用HTML在tumblr博客中为我的图像按钮添加声音效果

时间:2015-01-07 20:31:31

标签: javascript html

我的Tumblr博客上有六个图像按钮,当我将鼠标悬停在图像上时,我希望添加this音效。 每个按钮的设置如下:

<form name="mybutton" action="insert link here" method="POST">
    <div style="position: absolute; left: 247px; top: 204px;"> 
         <input type="image"  id="button" src="insert image here " onMouseOver="this.src='insert image here'" onMouseOut="this.src='insert image here'"/>
    </div>
</form> 

然而,无论我做什么,我都无法让它发挥作用。如果可能的话,我想保持简单。有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

此HTML:

<audio id="audioImagePlay" style="display:none">
    <source src="url to your audio source" />
</audio>

这个JavaScript:

<script>
    //get the button element and attach the onmouseover event handler to it. When mouse over fires execute function playAudio.
    document.getElementById("button").addEventListener("mouseover", playAudio, false);

    function playAudio()
    {
       //get audio element and initiate play.
       document.getElementById("audioImagePlay").play();
    }
</script>

应该为你做。