js音乐播放器

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .content {
            width: 100%;
            height: 650px;
            position: relative;
            background: #000;
            background-size: cover;
            background-position: 100% 100%;
            background-repeat: no-repeat;
        }
        
        img {
            width: 100%;
            vertical-align: middle;
        }
        
        .clearfix::after {
            display: block;
            content: "";
            clear: both;
        }
        
        .content .singerContent {
            margin-top: 100px;
            z-index: 100;
            position: absolute;
            left: 50%;
            width: 840px;
            margin: 100px 0 0 -390px;
        }
        
        #blurBg {
            background-image: url("../img/七里香.jpg");
            height: 720px;
        }
        
        .content #blurBg {
            width: 100%;
            opacity: 0.6;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 9;
            filter: blur(90px);
            background-repeat: no-repeat;
            background-size: cover;
        }
        
        .content .album {
            width: 262px;
        }
        
        .fl {
            float: left;
        }
        
        .content .songContent {
            width: 460px;
            min-height: 500px;
            margin-top: -7px;
            margin-left: 116px;
        }
        
        .content .albumImg {
            width: 262px;
            height: 262px;
            margin-bottom: 25px;
        }
        
        .content .albumImg img {
            border: none;
            width: 260px;
            height: 260px;
        }
        
        .btnDownloadClient {
            display: block;
            width: 230px;
            height: 50px;
            background: url(../img/downlaod_bg.png) no-repeat;
            cursor: pointer;
        }
        
        .content .btnArea2 {
            margin-top: 40px;
            padding-left: 16px;
        }
        
        .btnDownloadClient:hover {
            background-position: -231px 0;
        }
        
        .content .songContent .songName {
            font-size: 24px;
            font-style: normal;
            color: #fff;
            width: 460px;
        }
        
        .btnMv {
            float: left;
            width: 25px;
            height: 13px;
            margin: 15px 0 0 10px;
        }
        
        .icon {
            cursor: pointer;
            background: url(../img/btn.png) 0 -214px;
            background-repeat: no-repeat;
        }
        
        .audioName {
            float: left;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 420px;
        }
        
        .content .songContent .songDetail .albumName {
            margin-right: 10px;
        }
        
        .content .songContent .songDetail .albumName,
        .content .songContent .songDetail .singerName {
            display: block;
            width: 225px;
            height: 24px;
            line-height: 24px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 15px;
            color: #fff;
        }
        
        .fontColor {
            opacity: .6;
        }
        
        .content .songContent .songDetail .albumName a,
        .content .songContent .songDetail .singerName a {
            float: none;
            color: #fff;
            padding-right: 5px;
        }
        
        a {
            text-decoration: none;
            outline: none;
        }
        
        .content .songContent .songWordContent {
            outline: 0;
            height: 410px;
            margin-top: 17px;
            overflow: hidden;
            font-size: 15px;
            color: #fff;
            line-height: 30px;
            width: 410px;
            position: relative;
        }
        
        .content .songContent .songWordContent p.playOver {
            color: #01e5ff;
            opacity: 1;
        }
        
        .jspPane {
            position: absolute;
            transition: top 0.3s linear;
        }
        
        .content .songContent .songWordContent p {
            width: 420px;
            height: 34px;
            font-size: 15px;
            white-space: normal;
            overflow: hidden;
            text-overflow: ellipsis;
            opacity: 0.6;
            display: flex;
        }
        
        audio {
            width: 300px;
            display: block;
            margin: 0 auto;
        }
        
        .content #blurBg,
        .content .blurBgMask {
            width: 100%;
            height: 100%;
            opacity: .6;
        }
        
        .content .blurBgMask {
            background-color: #292a2b;
            background-color: rgba(0, 0, 0, .35);
            z-index: 10;
        }
    </style>
</head>

<body>
    <div class="content">
        <div class="singerContent clearfix">
            <div class="album fl">
                <div class="albumImg">
                    <a href="javascript:;" class="fl">
                        <img src="img/七里香.jpg" alt="">
                    </a>
                </div>
                <div class="btnArea2 clearfix">
                    <a class="btnDownloadClient"></a>
                </div>
            </div>
            <div class="songContent fl">
                <div class="songName clearfix" title=""><span class="audioName" title="七里香">七里香</span>
                    <span class="icon btnMv"></span>
                </div>
                <div class="songDetail clearfix">
                    <p class="albumName fl">
                        <span class="fontColor">专辑:</span>
                        <a href="javascript:;">七里香</a>
                    </p>
                    <p class="singerName fl" title="SWIN-S"><span class="fontColor">歌手:</span><a href="javascript:;">周杰伦</a></p>
                </div>

                <div class="songWordContent">
                    <!-- 歌词部分 -->
                    <div class="jspPane">
                    </div>
                </div>
            </div>
        </div>
        <div class="blurBgMask"></div>
        <div id="blurBg"></div>
    </div>
    <!-- 引入歌曲 -->
    <audio src="data/周杰伦 - 七里香.mp3" controls></audio>
    <!-- 引入jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- 引入歌曲 -->
    <script src="data/data.js"></script>
    <script>
        /* 将歌词拆分为两组   一组为时间  一组为歌词 */
        /* 时间 */
        let timeArr = [];
        /* 歌词 */
        let lrcArr = [];
        /* 使用正则表达式分割 */
        let reg = /\[(\d{2}:\d{2})\.\d{2}\](.+)/g
        let res = reg.exec(lrcStr)
        while (res) {
            timeArr.push(res[1]);
            lrcArr.push(res[2]);
            res = reg.exec(lrcStr)
        }
        /* 把歌词显示到页面中 */
        for (i = 0; i < lrcArr.length; i++) {
            $(".jspPane").append(`<p>${lrcArr[i]}</p>`)
        }
        /* 当播放器的时间发生变化时触发(只要播放就会触发) */
        $("audio").on("timeupdate", function() {
            //获取当前播放时间 this.currentTime
            // 格式划转 将 01:05:44 =》01:05  65 =》 01:05
            let m = parseInt(this.currentTime / 60); //分
            let s = parseInt(this.currentTime % 60); //秒
            let str = `${m.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`;
            //寻找当前时间对应的数组下标
            for (let i = 0; i < timeArr.length; i++) {
                if (str == timeArr[i]) {
                    $(".jspPane p").eq(i).addClass("playOver").siblings().removeClass("playOver")
                        //  让jspPane向上移动
                    if (i >= 4) {
                        $(".jspPane").css("top", (i - 4) * -34);
                    } else {
                        $(".jspPane").css("top", 0);
                    }
                }
            }
        })
    </script>
</body>

</html>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值