前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HTML5播放暂停音乐

HTML5播放暂停音乐

作者头像
全栈程序员站长
发布2022-07-15 14:47:07
8450
发布2022-07-15 14:47:07
举报

大家好,又见面了,我是全栈君

查看效果:http://hovertree.com/code/jquery/ueyf7gn4.htm

代码如下:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>jQuery播放音乐 - 何问起</title><base target=_blank />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
<link rel="stylesheet" href="http://hovertree.com/ziyuan/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
   <div class="playHovertree btn btn-primary">播放</div>
<div class="pauseHovertree btn btn-primary">暂停</div>
<script src="http://hovertree.com/ziyuan/jquery/jquery-2.2.0.min.js"></script>

<script>
    $(document).ready(function() {
        var audioElementHovertree = document.createElement('audio');
        audioElementHovertree.setAttribute('src', 'http://cms.hovertree.com/hovertreesound/hovertreesnow.mp3');
        audioElementHovertree.setAttribute('autoplay', 'autoplay'); //打开自动播放
        //audioElement.load()
 
        $.get();
 
        audioElementHovertree.addEventListener("load", function() {
            audioElementHovertree.play();
        }, true);
 
        $('.playHover'+'tree').click(function() {
            audioElementHovertree.play();
        });
 
        $('.pauseH'+'overtree').click(function() {
            audioElementHovertree.pause();
        });
    });</script>
    <br /><br />
    By <a href="http://hovertree.com">何问起</a> <a href="http://hovertree.com/code/">代码</a>
</body>
</html>

更多特效:http://www.cnblogs.com/roucheng/p/texiao.html

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/120646.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年12月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档