无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
<div id="aplayer-{{ | <includeonly> | ||
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.css"> | |||
<script src="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.js"></script> | |||
<div id="aplayer-{{{id}}}" class="aplayer-box"></div> | |||
<script> | <script> | ||
(function() { | (function() { | ||
// 颜色有效性检测 | |||
container | const isValidColor = (color) => { | ||
const style = new Option().style; | |||
style.color = color; | |||
return style.color !== ''; | |||
}; | |||
// 容器配置 | |||
const container = document.getElementById('aplayer-{{{id}}}'); | |||
audio: | const defaultColor = '#2980b9'; | ||
// 主题色处理 | |||
let themeColor = '{{{theme}}}'.trim(); | |||
if (!isValidColor(themeColor)) { | |||
themeColor = defaultColor; | |||
console.warn('无效的颜色值,已恢复默认'); | |||
} | |||
// 播放器配置 | |||
const ap = new APlayer({ | |||
container: container, | |||
theme: themeColor, | |||
audio: JSON.parse({{{songs}}}), | |||
autoplay: {{{autoplay|false}}}, | |||
customAudioType: {}, // 防止预加载错误 | |||
lrcType: 0, | |||
mutex: true | |||
}); | }); | ||
// | // 动态应用主题色 | ||
if (window. | const applyTheme = () => { | ||
const elements = container.querySelectorAll('.aplayer-bar-wrap, .aplayer-volume-wrap'); | |||
} | elements.forEach(el => { | ||
el.style.backgroundColor = `${themeColor}33`; // 添加透明度 | |||
}); | |||
container.querySelector('.aplayer-info').style.borderColor = themeColor; | |||
}; | |||
applyTheme(); | |||
// 窗口变化监听 | |||
window.addEventListener('resize', () => { | |||
if(window.innerWidth <= 768) { | |||
ap.list.show(); | |||
} | |||
}); | |||
})(); | })(); | ||
</script> | </script> | ||
< | |||
{{ | <style> | ||
</ | /* 动态主题色增强 */ | ||
.aplayer-box .aplayer-time { | |||
border-top-color: {{{theme|#2980b9}}} !important; | |||
} | |||
.aplayer-box .aplayer-icon path { | |||
fill: {{{theme|#2980b9}}}; | |||
} | |||
@media screen and (max-width: 768px) { | |||
.aplayer-box .aplayer-controller { | |||
background: linear-gradient(90deg, {{{theme|#2980b9}}} 0%, #{darken({{{theme|#2980b9}}}, 10%)} 100%); | |||
} | |||
} | |||
</style> | |||
</includeonly> | |||