简体   繁体   English

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

[英]Need help adding a sound effect to my image button in tumblr blog using HTML

I have six image buttons on my Tumblr blog that I want to add this sound effect to play when I hover over the image. 我在Tumblr博客上有六个图像按钮,当我将鼠标悬停在图像上时,我想添加声音效果来播放。 Each button is set up like: 每个按钮的设置如下:

<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> 

However, no matter what I do, I can't get it to work. 但是,无论我做什么,我都无法正常工作。 I would like to keep it simple if possible. 如果可能的话,我想保持简单。 Can someone help me? 有人能帮我吗?

This HTML: 此HTML:

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

And this JavaScript: 而这个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>

Should do it for you. 应该为你做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM