这篇记录左下角 APlayer 的美化过程:从默认的白色小方块,改成玻璃卡片 + 自动收起 + 暗色适配。播放器是 APlayer 内核加一个自己写的 nav-music.js 搭起来的,美化只动 CSS;照着「放内核 → 放脚本 → 挂载 → 放皮肤」的顺序做,就能复现同样的效果。

先看清楚结构

左边这个播放器不是 hexo-tag-aplayer 注入的,而是站里自己用脚本建的,一共三部分:

  • APlayer 1.10.1 内核:本地的 /js/APlayer.min.js 和 /css/APlayer.min.css;
  • nav-music.js:拉歌单、用 new APlayer({ container: '#nav-music', fixed: true, mini: true, ... }) 建播放器;
  • aplayer-fixed.css:本文的皮肤,只改样式。

歌单来自 api.i-meto.com/meting/api(网易云歌单 2331639478),音频走网易云外链 music.163.com/song/media/outer/url?id=歌曲ID.mp3——比 Meting 返回的直链稳,不会两三秒就 404 跳过。

渲染出来的 DOM 是这样:#nav-music 自己被加上 aplayer aplayer-fixed aplayer-narrow 这些类,卡片是里面的 .aplayer-body。暂停时 APlayer 自己加 .aplayer-narrow,所以「收起成封面」不用写 JS,CSS 接住这个类就行。

开始之前:准备文件

整个美化涉及 5 个文件,都不改主题源码:

文件 作用
[Blogroot]/source/js/APlayer.min.js APlayer 1.10.1 内核(本地化,也可以换 CDN)
[Blogroot]/source/css/APlayer.min.css APlayer 默认样式
[Blogroot]/source/js/nav-music.js 新建:拉歌单 + 建播放器
[Blogroot]/source/css/aplayer-fixed.css 新建:本文的皮肤
[Blogroot]/_config.butterfly.yml 注入 div、CSS 和两个脚本

第一步:nav-music.js

文件:[Blogroot]/source/js/nav-music.js | 改法:新建,整段写入。

展开查看 nav-music.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* 左下角固定迷你播放器
* 歌单仍由 Meting 接口提供,但音频直链改为网易云外链:
* https://music.163.com/song/media/outer/url?id=<songid>.mp3
* 原因:Meting 的 type=url 直链经常 404 / 超时,APlayer 遇到错误会在 2 秒后自动跳过。
*/
(function () {
"use strict";

var PLAYLIST_ID = "2331639478";
// 只保留实测可用的接口:qjqq.cn 403、injahow.cn 404,会在控制台报 CORS 错误
var APIS = [
"https://api.i-meto.com/meting/api"
];
var OUTER_URL = "https://music.163.com/song/media/outer/url?id=";
var FALLBACK_COVER = "/img/HG.JPG";
var CACHE_KEY = "cookiesky.navmusic.playlist.v2";
var CACHE_TTL = 6 * 60 * 60 * 1000;
var FETCH_TIMEOUT = 10000;
var CONTAINER_ID = "nav-music";

function pickId(item) {
var id = item.songid || item.id || "";
if (!id) {
var matched = String(item.url || "").match(/[?&]id=(\d+)/);
if (matched) id = matched[1];
}
return id ? String(id) : "";
}

function toTrack(item) {
var id = pickId(item);
if (!id) return null;
return {
name: item.title || item.name || "未知歌曲",
artist: item.author || item.artist || "未知歌手",
// 主用网易云外链,稳定且不依赖第三方接口
url: OUTER_URL + encodeURIComponent(id) + ".mp3",
// 外链失效时用接口直链兜底
fallback: item.url || "",
cover: item.pic || item.cover || FALLBACK_COVER,
lrc: item.lrc || "",
type: "auto"
};
}

function normalize(data) {
if (!Array.isArray(data)) return [];
return data.map(toTrack).filter(function (track) {
return track && track.url;
});
}

function readCache() {
try {
var raw = localStorage.getItem(CACHE_KEY);
if (!raw) return null;
var data = JSON.parse(raw);
if (!data || !Array.isArray(data.tracks) || !data.tracks.length) return null;
return {
tracks: data.tracks,
fresh: Date.now() - (data.at || 0) < CACHE_TTL
};
} catch (err) {
return null;
}
}

function saveCache(tracks) {
try {
localStorage.setItem(CACHE_KEY, JSON.stringify({
tracks: tracks,
at: Date.now()
}));
} catch (err) {}
}

function fetchJson(url) {
return new Promise(function (resolve, reject) {
var controller = typeof AbortController !== "undefined" ? new AbortController() : null;
var timer = setTimeout(function () {
if (controller) controller.abort();
reject(new Error("timeout"));
}, FETCH_TIMEOUT);

fetch(url, {
cache: "no-store",
signal: controller ? controller.signal : undefined
})
.then(function (res) {
if (!res.ok) throw new Error("HTTP " + res.status);
return res.json();
})
.then(function (data) {
clearTimeout(timer);
resolve(data);
})
.catch(function (err) {
clearTimeout(timer);
reject(err);
});
});
}

function fetchPlaylist() {
// 多镜像同时请求,谁先返回可用歌单就用谁
var attempts = APIS.map(function (api) {
return fetchJson(api + "?server=netease&type=playlist&id=" +
encodeURIComponent(PLAYLIST_ID) + "&r=" + Date.now());
});

return new Promise(function (resolve, reject) {
var pending = attempts.length;
var lastError = null;
if (!pending) {
reject(new Error("no api"));
return;
}
attempts.forEach(function (attempt) {
attempt.then(function (data) {
var tracks = normalize(data);
if (!tracks.length) throw new Error("empty playlist");
resolve(tracks);
}).catch(function (err) {
lastError = err;
pending -= 1;
if (pending === 0) reject(lastError || new Error("playlist failed"));
});
});
});
}

function whenAPlayerReady(callback) {
if (typeof window.APlayer !== "undefined") {
callback();
return;
}
var tries = 0;
var timer = setInterval(function () {
if (typeof window.APlayer !== "undefined") {
clearInterval(timer);
callback();
} else if (++tries > 80) {
clearInterval(timer);
}
}, 250);
}

function bindFallback(player) {
// APlayer 默认在音频报错 2 秒后跳过。这里先尝试用接口直链补救,
// 补救期间拦截一次 skipForward,避免刚切到兜底链接就被跳过。
var originalSkip = player.skipForward;

player.skipForward = function () {
if (player.__navRetrying) {
player.__navRetrying = false;
return;
}
return originalSkip.apply(player, arguments);
};

player.on("listswitch", function () {
player.__navRetried = false;
player.__navRetrying = false;
});

player.on("error", function () {
var audios = player.list && player.list.audios;
var track = audios && audios[player.list.index];
if (!track || !track.fallback || player.__navRetried) return;
if (track.url === track.fallback) return;

player.__navRetried = true;
player.__navRetrying = true;
player.audio.src = track.fallback;
player.audio.load();
var played = player.audio.play();
if (played && played.catch) played.catch(function () {});
});
}

function build(tracks) {
if (window.__navMusicPlayer) return;
// 不再预探测封面:逐张探测会额外产生上百个请求(Edge 下明显卡顿),
// 且网易云封面在多数网络下能正常加载,直接用真实封面即可。
buildNow(tracks);
}

function buildNow(tracks) {
if (window.__navMusicPlayer) return;
var container = document.getElementById(CONTAINER_ID);
if (!container || typeof window.APlayer === "undefined" || !tracks.length) return;

var player = new window.APlayer({
container: container,
audio: tracks,
fixed: true,
mini: true,
autoplay: false,
mutex: true,
lrcType: 1,
listFolded: false,
preload: "none",
order: "random",
theme: "#2980b9",
storageName: "cookiesky-nav-music"
});

window.__navMusicPlayer = player;
window.aplayers = window.aplayers || [];
window.aplayers.push(player);
bindFallback(player);
}

function start() {
if (!document.getElementById(CONTAINER_ID)) return;

var cached = readCache();
if (cached && cached.fresh) {
whenAPlayerReady(function () {
build(cached.tracks);
});
return;
}

whenAPlayerReady(function () {
fetchPlaylist()
.then(function (tracks) {
saveCache(tracks);
build(tracks);
})
.catch(function () {
if (cached && cached.tracks.length) build(cached.tracks);
});
});
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", start, false);
} else {
start();
}
})();

几个可以按自己情况改的地方:

  • PLAYLIST_ID:换成自己的网易云歌单 ID;
  • APIS:目前只留了 api.i-meto.com,换接口时保证返回 [{ title, author, songid/pic }] 这种结构;
  • 歌单结果缓存在 localStorage 里 6 小时,接口挂了会先用缓存;
  • 音频默认用网易云外链,失败时才回退到接口给的直链。

第二步:挂到页面上

文件:[Blogroot]/_config.butterfly.yml | 改法:在 inject 里加入容器、样式和脚本,顺序别乱。

1
2
3
4
5
6
7
8
inject:
head:
- <link rel="stylesheet" href="/css/APlayer.min.css">
- <link rel="stylesheet" href="/css/aplayer-fixed.css"> # 本文的皮肤
bottom:
- <div id="nav-music" class="no-destroy"></div>
- <script defer src="/js/APlayer.min.js"></script>
- <script defer src="/js/nav-music.js"></script>

#nav-music 是播放器容器,no-destroy 是为了 pjax 跳转时不删它;APlayer.min.js 必须先于 nav-music.js 加载,脚本里用 defer 时要保持这个先后顺序。

一、定位:从右下角挪到左下角

APlayer 的 fixed 模式默认贴着右下角,阴影也加在外层容器上。这里把位置统一改成 left: 18px; bottom: 18px,外层透明、去阴影,阴影只留在卡片上,视觉上才像「浮」着的一张卡。

1
2
3
4
5
6
7
8
.aplayer.aplayer-fixed {
left: 18px !important;
bottom: 18px !important;
right: auto !important;
max-width: 420px !important;
background: transparent !important;
box-shadow: none !important;
}

二、收起与展开:宽度必须分两段写

这是最容易踩的坑:把 left/right 改掉之后,APlayer 原来那套「展开时靠 right: 0 撑开」的规则失效,卡片会缩成封面的宽度。解决办法是给两个状态各自定宽:

1
2
3
4
5
6
7
8
9
10
/* 收起:只露一个方形封面 */
.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
width: 66px !important;
padding-right: 0 !important;
}

/* 展开:固定卡片宽度 */
.aplayer.aplayer-fixed:not(.aplayer-narrow) .aplayer-body {
width: 402px !important;
}

以后想改宽,三处要一起改:收起、展开、手机端媒体查询,否则切换状态会跳一下。

三、玻璃卡:背景、描边、模糊与阴影

卡片本体用半透明白 + 背景模糊,边框留一圈高光,阴影用偏蓝的深色,显得干净一点:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.aplayer.aplayer-fixed .aplayer-body {
border-radius: 18px !important;
background: rgba(255, 255, 255, 0.92) !important;
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: 0 14px 34px rgba(16, 42, 67, 0.28), 0 2px 8px rgba(16, 42, 67, 0.12);
backdrop-filter: blur(16px) saturate(160%) !important;
-webkit-backdrop-filter: blur(16px) saturate(160%) !important;
transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease !important;
}

.aplayer.aplayer-fixed .aplayer-body:hover {
transform: translateY(-3px);
box-shadow: 0 20px 44px rgba(16, 42, 67, 0.34), 0 4px 12px rgba(16, 42, 67, 0.16);
}

四、封面与播放按钮

封面自己带一层渐变遮罩,压住原图的杂色;播放按钮做成渐变圆钮,悬停放大:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.aplayer.aplayer-fixed .aplayer-pic {
border-radius: 15px;
overflow: hidden;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.aplayer.aplayer-fixed .aplayer-pic::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(73, 177, 245, 0.18), rgba(57, 197, 187, 0.1));
pointer-events: none;
}

.aplayer.aplayer-fixed .aplayer-pic .aplayer-button {
background: linear-gradient(135deg, rgba(73, 177, 245, 0.9), rgba(57, 197, 187, 0.9)) !important;
border: 1px solid rgba(255, 255, 255, 0.55);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(6px);
}

.aplayer.aplayer-fixed .aplayer-pic .aplayer-button:hover {
transform: scale(1.1);
}

五、歌名、进度条与图标

歌名太长会把卡片撑开,所以标题和歌手都要省略号,标题再限个最大宽度:

1
2
3
4
5
6
7
8
9
10
.aplayer.aplayer-fixed .aplayer-title {
max-width: 62%;
}

.aplayer.aplayer-fixed .aplayer-title,
.aplayer.aplayer-fixed .aplayer-author {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

进度条加粗到 3px,已播放部分直接用主题色做渐变,这样美化面板换主题色时它也跟着变:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.aplayer.aplayer-fixed .aplayer-controller .aplayer-bar {
height: 3px;
border-radius: 999px;
background: rgba(20, 50, 74, 0.14) !important;
}

.aplayer.aplayer-fixed .aplayer-controller .aplayer-played {
border-radius: 999px;
background: linear-gradient(90deg, var(--theme-color), color-mix(in srgb, var(--theme-color) 62%, #fff)) !important;
}

.aplayer.aplayer-fixed .aplayer-info .aplayer-icon:hover svg path {
fill: var(--theme-color) !important;
}

六、歌单列表

列表也做成浮起来的玻璃面板,当前播放项用主题色浅底,滚动条单独美化:

1
2
3
4
5
6
7
8
9
10
.aplayer.aplayer-fixed .aplayer-list {
margin-bottom: 80px !important;
border: 1px solid rgba(255, 255, 255, 0.45) !important;
border-radius: 18px !important;
overflow: hidden !important;
}

.aplayer.aplayer-fixed .aplayer-list-light {
background: rgba(73, 177, 245, 0.14) !important;
}

七、暗色模式

暗色只覆盖颜色,不动尺寸和布局:卡片背景换成深色玻璃,文字、图标、列表底色各自调亮一档。

1
2
3
4
5
6
7
8
9
[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-body {
background: rgba(20, 24, 32, 0.94) !important;
border-color: rgba(255, 255, 255, 0.12);
box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-title { color: #eef6ff !important; }
[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-author { color: #9db4c8 !important; }
[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-info .aplayer-icon svg path { fill: #cfe0ef !important; }

八、手机端

窄屏时离边角近一点,展开宽度直接吃满屏宽,不要固定 402px:

1
2
3
4
5
6
7
8
9
10
11
@media screen and (max-width: 768px) {
.aplayer.aplayer-fixed,
.aplayer.aplayer-fixed .aplayer-body {
left: 12px !important;
bottom: 12px !important;
}

.aplayer.aplayer-fixed:not(.aplayer-narrow) .aplayer-body {
width: calc(100vw - 24px) !important;
}
}

完整样式

展开查看 aplayer-fixed.css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*!
* APlayer 左下角固定播放器皮肤
* 适用:APlayer 1.10.x + fixed 模式(.aplayer.aplayer-fixed)
* 说明:颜色、圆角、尺寸都集中在文件顶部与各段注释里,按需改。
*/

/* ===== 左下角音乐播放器美化 ===== */
.aplayer.aplayer-fixed {
left: 18px !important;
bottom: 18px !important;
right: auto !important;
max-width: 420px !important;
z-index: 1000 !important;
background: transparent !important;
box-shadow: none !important;
}

/* 主体:玻璃卡片 */
.aplayer.aplayer-fixed .aplayer-body {
left: 18px !important;
bottom: 18px !important;
right: auto !important;
border-radius: 18px !important;
overflow: hidden;
background: rgba(255, 255, 255, 0.92) !important;
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: 0 14px 34px rgba(16, 42, 67, 0.28), 0 2px 8px rgba(16, 42, 67, 0.12);
backdrop-filter: blur(16px) saturate(160%) !important;
-webkit-backdrop-filter: blur(16px) saturate(160%) !important;
padding-right: 16px !important;
z-index: 1000 !important;
transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease !important;
}

/* 收起时只显示方形封面 */
.aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
width: 66px !important;
padding-right: 0 !important;
box-shadow: 0 10px 28px rgba(16, 42, 67, 0.32), 0 0 24px rgba(73, 177, 245, 0.35) !important;
}

/* 展开时固定卡片宽度(否则 left/right 被改后会缩成封面宽) */
.aplayer.aplayer-fixed:not(.aplayer-narrow) .aplayer-body {
width: 402px !important;
}

.aplayer.aplayer-fixed .aplayer-body:hover {
transform: translateY(-3px);
box-shadow: 0 20px 44px rgba(16, 42, 67, 0.34), 0 4px 12px rgba(16, 42, 67, 0.16);
}

/* 封面 */
.aplayer.aplayer-fixed .aplayer-pic {
position: relative;
border-radius: 15px;
overflow: hidden;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.aplayer.aplayer-fixed .aplayer-pic::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(73, 177, 245, 0.18), rgba(57, 197, 187, 0.1));
pointer-events: none;
}

/* 播放按钮:渐变圆钮 */
.aplayer.aplayer-fixed .aplayer-pic .aplayer-button {
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, rgba(73, 177, 245, 0.9), rgba(57, 197, 187, 0.9)) !important;
border: 1px solid rgba(255, 255, 255, 0.55);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
transition: transform 0.25s ease, background 0.25s ease;
}

.aplayer.aplayer-fixed .aplayer-pic .aplayer-button:hover {
background: rgba(73, 177, 245, 0.9) !important;
transform: scale(1.1);
}

/* 歌曲信息 */
.aplayer.aplayer-fixed .aplayer-info {
border-bottom: none !important;
background: transparent !important;
padding: 8px 4px 6px 10px !important;
}

.aplayer.aplayer-fixed .aplayer-title {
color: #16324a !important;
font-size: 14px;
font-weight: 700;
letter-spacing: 0.2px;
}

.aplayer.aplayer-fixed .aplayer-author {
color: #5d778c !important;
font-size: 12px;
}

/* 歌名/歌手过长时省略,避免把卡片撑开 */
.aplayer.aplayer-fixed .aplayer-music {
display: flex;
align-items: baseline;
overflow: hidden;
}

.aplayer.aplayer-fixed .aplayer-title,
.aplayer.aplayer-fixed .aplayer-author {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.aplayer.aplayer-fixed .aplayer-title {
max-width: 62%;
}

/* 进度条 */
.aplayer.aplayer-fixed .aplayer-controller .aplayer-bar-wrap {
margin: 8px 0 4px !important;
padding: 0 !important;
}

.aplayer.aplayer-fixed .aplayer-controller .aplayer-bar {
height: 3px;
border-radius: 999px;
background: rgba(20, 50, 74, 0.14) !important;
}

.aplayer.aplayer-fixed .aplayer-controller .aplayer-played {
border-radius: 999px;
background: linear-gradient(90deg, var(--theme-color), color-mix(in srgb, var(--theme-color) 62%, #fff)) !important;
}

.aplayer.aplayer-fixed .aplayer-controller .aplayer-thumb {
background: #ffffff !important;
box-shadow: 0 0 0 2px rgba(73, 177, 245, 0.5);
}

/* 时间与操作图标 */
.aplayer.aplayer-fixed .aplayer-time {
color: #6a8599 !important;
}

.aplayer.aplayer-fixed .aplayer-info .aplayer-icon svg path {
fill: #3f5f78 !important;
}

.aplayer.aplayer-fixed .aplayer-info .aplayer-icon:hover svg path {
fill: var(--theme-color) !important;
}

/* 播放列表:透明玻璃浮层 */
.aplayer.aplayer-fixed .aplayer-list {
margin-bottom: 80px !important;
border: 1px solid rgba(255, 255, 255, 0.45) !important;
border-radius: 18px !important;
overflow: hidden !important;
background: rgba(255, 255, 255, 0.74) !important;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 16px 38px rgba(16, 42, 67, 0.2) !important;
backdrop-filter: blur(22px) saturate(180%) !important;
-webkit-backdrop-filter: blur(22px) saturate(180%) !important;
position: relative !important;
z-index: 999 !important;
}

.aplayer.aplayer-fixed .aplayer-list ol {
max-height: 260px;
border-radius: 18px !important;
background: transparent !important;
overflow-y: auto;
}

.aplayer.aplayer-fixed .aplayer-list li {
color: #1f3a52 !important;
background: transparent !important;
border-bottom: 1px solid rgba(73, 177, 245, 0.12);
transition: background 0.2s ease;
}

.aplayer.aplayer-fixed .aplayer-list li:first-child {
border-radius: 18px 18px 0 0;
}

.aplayer.aplayer-fixed .aplayer-list li:last-child {
border-radius: 0 0 18px 18px;
}

.aplayer.aplayer-fixed .aplayer-list li:hover {
background: rgba(73, 177, 245, 0.12);
}

.aplayer.aplayer-fixed .aplayer-list-light {
background: rgba(73, 177, 245, 0.16) !important;
}

.aplayer.aplayer-fixed .aplayer-list-author {
color: #46617a !important;
}

/* 当前播放指示条 */
.aplayer.aplayer-fixed .aplayer-list-cur {
background: linear-gradient(180deg, var(--theme-color), color-mix(in srgb, var(--theme-color) 62%, #fff)) !important;
border-radius: 999px;
}

.aplayer.aplayer-fixed .aplayer-list-index {
color: #5b7488 !important;
}

/* 列表滚动条 */
.aplayer.aplayer-fixed .aplayer-list ol::-webkit-scrollbar {
width: 6px;
}

.aplayer.aplayer-fixed .aplayer-list ol::-webkit-scrollbar-thumb {
border-radius: 999px;
background: rgba(73, 177, 245, 0.35);
}

.aplayer.aplayer-fixed .aplayer-list ol::-webkit-scrollbar-track {
background: transparent;
}

/* 夜间模式 */
[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-body {
background: rgba(20, 24, 32, 0.94) !important;
border-color: rgba(255, 255, 255, 0.12);
box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-title {
color: #eef6ff !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-author {
color: #9db4c8 !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-time {
color: #8ca3b8 !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-info .aplayer-icon svg path {
fill: #cfe0ef !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-list {
background: rgba(18, 24, 32, 0.72) !important;
border-color: rgba(255, 255, 255, 0.12) !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-list-author {
color: #b9cede !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-list li {
color: #e8f2fb !important;
}

[data-theme="dark"] .aplayer.aplayer-fixed .aplayer-list-light {
background: rgba(73, 177, 245, 0.22) !important;
}

/* 小屏时离边角近一点,展开宽度自适应 */
@media screen and (max-width: 768px) {
.aplayer.aplayer-fixed,
.aplayer.aplayer-fixed .aplayer-body {
left: 12px !important;
bottom: 12px !important;
}

.aplayer.aplayer-fixed:not(.aplayer-narrow) .aplayer-body {
width: calc(100vw - 24px) !important;
}
}

代码放在哪

美化的核心是两份文件:source/css/aplayer-fixed.css(文末折叠里的完整样式)和 source/js/nav-music.js(第一步那份脚本),按上面的 inject 引进来即可。

三个容易漏的点:

  • 改完 CSS / JS 要把 inject 里的 ?v= 版本号升一次(本站是 ?v=20261121zf 这种格式),否则浏览器和 Service Worker 会继续用旧文件;
  • 开了 Service Worker 的话,sw.js 里的 VERSION 也要一起升;
  • 皮肤不一定要单独建文件,直接粘进 custom.css 也能用,只要保证在 APlayer 默认样式之后加载。

改完怎么验证

  1. 加载:首次打开页面,控制台没有跨域报错,播放器列表里能看到歌单曲目(本站歌单 188 首)。
  2. 收起:暂停状态左下角只剩一个 66px 的方形封面。
  3. 展开:鼠标移上去,卡片展开到 402px,有上浮和阴影变化。
  4. 换主题色:美化面板里改主题色,进度条、图标悬停色、列表高亮一起变。
  5. 暗色:切到夜间模式,卡片变深色玻璃,文字仍然清楚。
  6. 手机:390px 宽度下贴边 12px,展开占满屏宽,页面没有横向滚动。

附:aplayerInject 写法的参数

如果看的是 hexo-tag-aplayer 的标记写法:

1
2
3
4
<div id="aplayer-oSEOhviA" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="4895239160" data-server="netease" data-type="playlist"
data-mode="random" data-autoplay="false" data-listmaxheight="340px"
data-preload="auto" data-theme="#e3f2f5" data-volume="0.4" mutex="true"></div>
参数 说明 常用值
id 容器 ID,别和页面里别的元素重名 aplayer-oSEOhviA
class 固定类名,插件靠它识别标记,不要改 aplayer aplayer-tag-marker meting-tag-marker
data-id 歌单 / 歌曲 ID 4895239160
data-server 平台:netease 网易云、tencent QQ 音乐、kugou 酷狗、baidu 百度 netease
data-type 资源类型:playlist 歌单、song 单曲、album 专辑、artist 歌手 playlist
data-mode 播放模式:random 随机、order 顺序、single 单曲循环、circulation 列表循环 random
data-autoplay 自动播放,浏览器一般会拦截 false
data-listmaxheight 播放列表最大高度 340px
data-preload 预加载:none / metadata / auto auto
data-theme 进度条与高亮色 #e3f2f5
data-volume 初始音量,0–1 0.4
mutex 多个播放器互斥,同时只响一个 true

除了网易云还能选别的平台:把 data-server 改成 tencent(QQ 音乐)、kugou(酷狗)、baidu(百度)即可,data-id 也要换成对应平台的歌单 / 歌曲 ID。要注意两点:

  1. 能不能拉到数据取决于所用的 Meting 接口。本站实测 api.i-meto.com 对 tencent 返回空数组,网易云和酷狗正常;想用 QQ 音乐得换支持它的接口,或者自己搭一个 Meting API。
  2. 本站左下角播放器最终没走这套标记,而是用前面的 nav-music.js 直接建 APlayer——原因就是外链和接口稳定性更好控制。上面这张表供参考,如果你用 aplayerInject 才需要。

参考