Skip to content

Commit ba76929

Browse files
committed
new api: theme
1 parent e105283 commit ba76929

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/js/player.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,7 @@ class APlayer {
206206
else {
207207
this.template.pic.style.backgroundImage = '';
208208
}
209-
if (this.options.audio[this.playIndex].theme) {
210-
this.template.pic.style.backgroundColor = this.options.audio[this.playIndex].theme;
211-
this.template.played.style.background = this.options.audio[this.playIndex].theme;
212-
this.template.thumb.style.background = this.options.audio[this.playIndex].theme;
213-
this.template.volume.style.background = this.options.audio[this.playIndex].theme;
214-
}
209+
this.theme();
215210
this.template.title.innerHTML = this.options.audio[this.playIndex].name;
216211
this.template.author.innerHTML = this.options.audio[this.playIndex].artist ? ' - ' + this.options.audio[this.playIndex].artist : '';
217212
const light = this.container.getElementsByClassName('aplayer-list-light')[0];
@@ -244,6 +239,17 @@ class APlayer {
244239
});
245240
}
246241

242+
theme (color = this.options.audio[this.playIndex].theme, index = this.playIndex) {
243+
this.options.audio[index].theme = color;
244+
this.template.listCurs[index].style.backgroundColor = color;
245+
if (index === this.playIndex) {
246+
this.template.pic.style.backgroundColor = color;
247+
this.template.played.style.background = color;
248+
this.template.thumb.style.background = color;
249+
this.template.volume.style.background = color;
250+
}
251+
}
252+
247253
seek (time) {
248254
time = Math.max(time, 0);
249255
if (this.audio.duration) {

src/js/template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Template {
3232
this.button = this.container.querySelector('.aplayer-button');
3333
this.list = this.container.querySelector('.aplayer-list');
3434
this.listOl = this.container.querySelector('.aplayer-list ol');
35+
this.listCurs = this.container.querySelectorAll('.aplayer-list-cur');
3536
this.played = this.container.querySelector('.aplayer-played');
3637
this.loaded = this.container.querySelector('.aplayer-loaded');
3738
this.thumb = this.container.querySelector('.aplayer-thumb');

src/template/player.art

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
5353
{{each options.audio}}
5454
<li>
55-
<span class="aplayer-list-cur" style="background: {{ $value.theme || options.theme }};"></span>
55+
<span class="aplayer-list-cur" style="background-color: {{ $value.theme || options.theme }};"></span>
5656
<span class="aplayer-list-index">{{ $index + 1 }}</span>
5757
<span class="aplayer-list-title">{{ $value.name }}</span>
5858
<span class="aplayer-list-author">{{ $value.artist }}</span>

0 commit comments

Comments
 (0)