仿Heo音乐播放器
Rootlex

前言

在看到 Heo 的小药丸音乐播放器的设计,还挺好看的,于是便决定开抄

heo demo

引入音乐播放器

首先找到 _config.butterfly.ymlaplayer 引入打开

aplayerInject:
  enable: true
  per_page: true

启用音乐播放器

_config.butterfly.yml 中的 inject 加入一段代码

inject:
  head:
    - <link rel="stylesheet" href="/css/custom.css" type="text/css">
  bottom:
+    - <div id="nav-music" onclick="rootlex.musicToggle()"><div id="nav-music-hoverTips">音乐已暂停</div><meting-js id="1708664797" server="tencent" type="playlist" mutex="true" preload="none" data-lrctype="0" order="random"></meting-js></div>
    - <script data-pjax src="/js/waterfall.js"></script>
    - <script data-pjax src="/js/custom.js"></script>

参数解析

<meting-js id="1708664797" server="tencent" type="playlist" mutex="true" preload="none" data-lrctype="0" order="random"></meting-js>

参数功能
id歌单id
server音乐播放源 netease(网易), tencent(QQ音乐), kugou(酷狗), xiami(虾米), baidu(百度)
mutex防止多个播放器同时播放 开:true 关:false
theme播放器主色
orderramdon(随机播放) 或 list(顺序播放)

添加自定义CSS

通过 custom.css 引入样式

颜色样式

/* 颜色 */
:root {
  --rootlex-theme-op: #4259ef23;
  --rootlex-white: #fff;
  --rootlex-black: #000;
  --rootlex-none: rgba(0, 0, 0, 0);
  --rootlex-gray: #999999;
  --rootlex-yellow: #ffc93e;
  --rootlex-border-radius: 15px;
  --rootlex-main: var(--rootlex-theme);
  --rootlex-main-op: var(--rootlex-theme-op);
  --rootlex-shadow-theme: 0 8px 12px -3px var(--rootlex-theme-op);
  --rootlex-shadow-main: 0 8px 12px -3px var(--rootlex-main-op);
  --rootlex-shadow-blue: 0 8px 12px -3px rgba(40, 109, 234, 0.2);
  --rootlex-shadow-white: 0 8px 12px -3px rgba(255, 255, 255, 0.2);
  --rootlex-shadow-black: 0 0 12px 4px rgba(0, 0, 0, 0.05);
  --rootlex-shadow-yellow: 0px 38px 77px -26px rgba(255, 201, 62, 0.12);
  --rootlex-shadow-red: 0 8px 12px -3px #ee7d7936;
  --rootlex-shadow-green: 0 8px 12px -3px #87ee7936;
  --rootlex-shadow-border: 0 8px 16px -4px #2c2d300c;
  --rootlex-logo-color: linear-gradient(215deg, #4584ff 30%, #ff7676 70%);
  --style-border: 1px solid var(--rootlex-card-border);
  --rootlex-blue-main: #425aef;
  --style-border-hover: 1px solid var(--rootlex-main);
  --style-border-dashed: 1px dashed var(--rootlex-theme-op);
  --style-border-avatar: 4px solid var(--rootlex-background);
  --style-border-always: 1px solid var(--rootlex-card-border);
  --rootlex-white-acrylic1: #fefeff !important;
  --rootlex-white-acrylic2: #fcfdff !important;
  --rootlex-black-acrylic2: #08080a !important;
  --rootlex-black-acrylic1: #0b0b0e !important;
}

[data-theme='light'] {
  --rootlex-theme: #425aef;
  --rootlex-theme-op: #4259ef23;
  --rootlex-blue: #425aef;
  --rootlex-red: #d8213c;
  --rootlex-pink: #ff7c7c;
  --rootlex-green: #57bd6a;
  --rootlex-fontcolor: #363636;
  --rootlex-background: #f7f9fe;
  --rootlex-reverse: #000;
  --rootlex-maskbg: rgba(255, 255, 255, 0.6);
  --rootlex-maskbgdeep: rgba(255, 255, 255, 0.85);
  --rootlex-hovertext: var(--rootlex-theme);
  --rootlex-ahoverbg: #f7f7fa;
  --rootlex-lighttext: var(--rootlex-main);
  --rootlex-secondtext: rgba(60, 60, 67, 0.6);
  --rootlex-scrollbar: rgba(60, 60, 67, 0.4);
  --rootlex-card-btn-bg: #edf0f7;
  --rootlex-post-blockquote-bg: #fafcff;
  --rootlex-post-tabs-bg: #f2f5f8;
  --rootlex-secondbg: #edf0f7;
  --rootlex-shadow-nav: 0 5px 12px -5px rgba(102, 68, 68, 0.05);
  --rootlex-card-bg: #fff;
  --rootlex-shadow-lightblack: 0 5px 12px -5px rgba(102, 68, 68, 0);
  --rootlex-shadow-light2black: 0 5px 12px -5px rgba(102, 68, 68, 0);
  --rootlex-card-border: #c0c6d8;
}

[data-theme='dark'] {
  --rootlex-theme: #0084ff;
  --rootlex-theme-op: #0084ff23;
  --rootlex-blue: #0084ff;
  --rootlex-red: #ff3842;
  --rootlex-pink: #ff7c7c;
  --rootlex-green: #57bd6a;
  --rootlex-fontcolor: #f7f7fa;
  --rootlex-background: #18171d;
  --rootlex-reverse: #fff;
  --rootlex-maskbg: rgba(0, 0, 0, 0.6);
  --rootlex-maskbgdeep: rgba(0, 0, 0, 0.85);
  --rootlex-hovertext: #0a84ff;
  --rootlex-ahoverbg: #fff;
  --rootlex-lighttext: #f2b94b;
  --rootlex-secondtext: #a1a2b8;
  --rootlex-scrollbar: rgba(200, 200, 223, 0.4);
  --rootlex-card-btn-bg: #30343f;
  --rootlex-post-blockquote-bg: #000;
  --rootlex-post-tabs-bg: #121212;
  --rootlex-secondbg: #30343f;
  --rootlex-shadow-nav: 0 5px 20px 0px rgba(28, 28, 28, 0.4);
  --rootlex-card-bg: #1d1b26;
  --rootlex-shadow-lightblack: 0 5px 12px -5px rgba(102, 68, 68, 0);
  --rootlex-shadow-light2black: 0 5px 12px -5px rgba(102, 68, 68, 0);
  --rootlex-card-border: #42444a;
}

播放器样式

@media screen and (max-width: 1300px) {
    #nav-music {
        display: none !important;
    }
}

#nav-music {
    display: flex;
    align-items: center;
    z-index: 1001;
    position: fixed;
    bottom: 20px;
    left: 20px;
    cursor: pointer;
    transition: 0.3s;
    transform-origin: left bottom;
    box-shadow: var(--rootlex-shadow-border);
    border-radius: 40px;
    overflow: hidden;
}

#nav-music:active {
    transform: scale(0.97);
}

#nav-music.playing {
    box-shadow: 0 0 12px -3px var(--rootlex-none);
    -webkit-animation: playingShadow 5s linear infinite;
}

@-webkit-keyframes playingShadow {
    0% {
        box-shadow: 0 0 12px -3px var(--rootlex-none);
    }

    50% {
        box-shadow: 0 0 12px 0 var(--rootlex-main);
    }

    100% {
        box-shadow: 0 0 12px -3px var(--rootlex-none);
    }
}

#nav-music .aplayer.aplayer-withlrc .aplayer-pic {
    height: 25px;
    width: 25px;
    border-radius: 40px;
    z-index: 1;
    transition: 0.3s;
    -webkit-transform: rotate(0deg) scale(1);
    border: var(--style-border-always);
    -webkit-animation: changeright 24s linear infinite;
    animation-play-state: paused;
}

#nav-music.playing .aplayer.aplayer-withlrc .aplayer-pic {
    box-shadow: 0 0 14px #ffffffa6;
    -webkit-transform: rotate(0deg) scale(1.1);
    border-color: var(--rootlex-white);
    animation-play-state: running;
}

@-webkit-keyframes changeright {

    0% {
        -webkit-transform: rotate(0deg) scale(1.1);
        box-shadow: 0 0 2px #ffffff00;
    }

    25% {
        -webkit-transform: rotate(90deg) scale(1.1);
        box-shadow: 0 0 14px #ffffff;
    }

    50% {
        -webkit-transform: rotate(180deg) scale(1.1);
        box-shadow: 0 0 2px #ffffff00;
    }

    75% {
        -webkit-transform: rotate(270deg) scale(1.1);
        box-shadow: 0 0 14px #ffffff;
    }

    100% {
        -webkit-transform: rotate(360deg) scale(1.1);
        box-shadow: 0 0 2px #ffffff00;
    }
}

#nav-music .aplayer.aplayer-withlrc .aplayer-info {
    height: 100%;
    color: var(--rootlex-fontcolor);
    margin-left: 8px;
    padding: 0;
    display: flex;
    align-items: center;
}

#nav-music.playing .aplayer.aplayer-withlrc .aplayer-info {
    color: var(--rootlex-white);
}

#nav-music #nav-music-hoverTips {
    color: var(--rootlex-white);
    background: var(--rootlex-main);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    align-items: center;
    justify-content: center;
    display: flex;
    border-radius: 40px;
    opacity: 0;
    font-size: 12px;
    z-index: 2;
    pointer-events: none;
    transition: 0.3s;
}

#nav-music:hover:not(.playing) #nav-music-hoverTips {
    opacity: 1;
}

#nav-music.playing #nav-music-hoverTips {
    opacity: 0;
}

#nav-music .aplayer {
    background: var(--card-bg);
    border-radius: 60px;
    height: 41px;
    display: flex;
    margin: 0;
    pointer-events: none;
    transition: 0.3s;
    border: var(--style-border);
    box-shadow: none;
    width: auto !important;
}

#nav-music.playing .aplayer {
    background: #0084ffdd;
    border: var(--style-border-hover);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

#nav-music .aplayer .aplayer-notice {
    display: none;
}

#nav-music .aplayer .aplayer-miniswitcher {
    display: none;
}

#nav-music .aplayer .aplayer-body {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 12px 0 8px;
    height: 100%;
    width: 100%;
}

#nav-music .aplayer .aplayer-pic .aplayer-play {
    opacity: 0;
}

#nav-music .aplayer-list {
    display: none;
}

#nav-music .aplayer .aplayer-info .aplayer-music {
    margin: 0;
    display: flex;
    align-items: center;
    padding: 0;
    z-index: 1;
}

#nav-music .aplayer .aplayer-info .aplayer-controller .aplayer-time {
    display: none;
}

#nav-music .aplayer .aplayer-info .aplayer-music .aplayer-author {
    display: none;
}

#nav-music .aplayer.aplayer-withlist .aplayer-info {
    border: none;
    display: flex !important;
}

#nav-music .aplayer .aplayer-pic div {
    border: none;
}

#nav-music .aplayer .aplayer-info .aplayer-music .aplayer-title {
    cursor: pointer;
    line-height: 1;
    display: inline-block;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: 0.3s;
}

#nav-music .aplayer .aplayer-info .aplayer-controller {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#nav-music .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap {
    margin: 0;
    padding: 0;
}

#nav-music .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar {
    height: 100%;
    background: none;
}

#nav-music .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-loaded {
    display: none;
}

#nav-music .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played {
    height: 100%;
    opacity: 0.1;
    background-color: var(--rootlex-white) !important;
    -webkit-animation: lightBar 5s ease infinite;
    animation-play-state: paused;
}

#nav-music.playing .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played {
    animation-play-state: running;
}

@-webkit-keyframes lightBar {

    0% {
        opacity: 0.1;
    }

    60% {
        opacity: 0.3;
    }

    100% {
        opacity: 0.1;
    }
}


/* 歌词 */
#nav-music .aplayer.aplayer-withlrc .aplayer-lrc {
    width: 0;
    opacity: 0;
    transition: 0.3s;
    margin-left: 8px;
    margin-top: -2px;
}

#nav-music.playing .aplayer.aplayer-withlrc .aplayer-lrc {
    width: 200px;
    margin-bottom: 0;
    opacity: 1;
}

#nav-music .aplayer .aplayer-lrc p.aplayer-lrc-current {
    color: var(--rootlex-white);
    border: none;
}

#nav-music .aplayer .aplayer-lrc:after,
#nav-music .aplayer .aplayer-lrc:before {
    display: none;
}

#nav-music .aplayer .aplayer-lrc p {
    color: #ffffffb3;
}

引入js

//音乐播放
var rootlex = {
    musicToggle: function(){
        if (rootlex_musicPlaying) {
            document.querySelector("#nav-music").classList.remove("playing");
            rootlex_musicPlaying = false;
            document.querySelector('meting-js').aplayer.pause();
        }else {
            document.querySelector("#nav-music").classList.add("playing");
            rootlex_musicPlaying = true;
            document.querySelector('meting-js').aplayer.play();
        }
    },
}