在JQuery/Javascript中使用暂停/播放图标实现背景音乐

Implement Background Music with Pause/Play Icon in JQuery/Javascript

本文关键字:播放 图标 实现 暂停 背景音乐 JQuery Javascript      更新时间:2023-09-26

您好,提前感谢您。我对 JQuery/Javascript 很陌生,不确定如何使用我的暂停/播放图标实现我的嵌入式背景音乐。任何帮助将不胜感激。提前感谢!

       <div id="toggle" class="play" style="width: 314px; height: 311px"></div>
       <script type="text/javascript"></script>

     $(document).ready(function() {
       $('#music').attr("class", "false");
        $('#toggle').bind("click", function() {
        if ($(this).attr("class") == "play")
        $(this).attr("class", "pause");

        else
        $(this).attr("class", "play");

        });
        });

声音被放置在一个空的跨度中

JavaScript 在启动

脚本时将嵌入标记放在空 span 标记内。因此,您需要在HTML页面正文中的某个位置添加以下span文件,最好在文档顶部附近添加:

<span id="dummy"></span>
Call the Script with an onmouseover or onclick Attribute

您需要添加的最后一件事是要在单击或鼠标悬停时生成声音的元素。使用以下属性之一调用脚本:

<a href="#" onclick="playSound('URL to soundfile');">Click here to hear a sound</a>
 <p onmouseover="playSound('URL to soundfile');">Mouse over this text to hear a sound</p>