Skip to content

Commit

Permalink
support multiple notices
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsuha committed Jul 14, 2021
1 parent 808dd62 commit 281334b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"comma-style": 1,
"func-call-spacing": 1,
"keyword-spacing": 1,
"linebreak-style": 1,
"linebreak-style": 0,
"no-multiple-empty-lines": 1,
"space-infix-ops": 1,
"arrow-spacing": 1,
Expand Down
61 changes: 50 additions & 11 deletions src/css/notice.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
.dplayer-notice {
opacity: 0;
.dplayer-notice-list{
position: absolute;
bottom: 60px;
left: 20px;
font-size: 14px;
border-radius: 2px;
background: rgba(28, 28, 28, 0.9);
padding: 7px 20px;
transition: all .3s ease-in-out;
overflow: hidden;
color: #fff;
pointer-events: none;
}

.dplayer-notice {
border-radius: 2px;
background: rgba(28, 28, 28, 0.9);
transition: all .3s ease-in-out;
overflow: hidden;
color: #fff;
display: table;
pointer-events: none;
animation: showNotice .3s ease 1 forwards;
}

.remove-notice{
animation: removeNotice .3s ease 1 forwards;
}
}

@keyframes showNotice {
from {
padding: 0;
font-size: 0;
margin-top: 0;
}
to {
padding: 7px 20px;
font-size: 14px;
margin-top: 5px;
}
}

@keyframes removeNotice {
0%{
padding: 7px 20px;
font-size: 14px;
margin-top: 5px;
}
20%{
font-size: 12px;
}
21%{
font-size: 0;
padding: 7px 10px;
}
100%{
padding: 0;
margin-top: 0;
font-size: 0;
}
}
27 changes: 17 additions & 10 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,24 @@ class DPlayer {
}

notice(text, time = 2000, opacity = 0.8) {
this.template.notice.innerHTML = text;
this.template.notice.style.opacity = opacity;
if (this.noticeTime) {
clearTimeout(this.noticeTime);
}
this.events.trigger('notice_show', text);
const notice = Template.NewNotice(text, opacity);

this.template.noticeList.appendChild(notice);
this.events.trigger('notice_show', notice);

if (time > 0) {
this.noticeTime = setTimeout(() => {
this.template.notice.style.opacity = 0;
this.events.trigger('notice_hide');
}, time);
setTimeout(
(function (e, dp) {
return () => {
e.addEventListener('animationend', () => {
dp.template.noticeList.removeChild(e);
});
e.classList.add('remove-notice');
dp.events.trigger('notice_hide');
};
})(notice, this),
time
);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/js/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Template {
this.qualityButton = this.container.querySelector('.dplayer-quality-icon');
this.barPreview = this.container.querySelector('.dplayer-bar-preview');
this.barWrap = this.container.querySelector('.dplayer-bar-wrap');
this.notice = this.container.querySelector('.dplayer-notice');
this.noticeList = this.container.querySelector('.dplayer-notice-list');
this.infoPanel = this.container.querySelector('.dplayer-info-panel');
this.infoPanelClose = this.container.querySelector('.dplayer-info-panel-close');
this.infoVersion = this.container.querySelector('.dplayer-info-panel-item-version .dplayer-info-panel-item-data');
Expand All @@ -99,6 +99,14 @@ class Template {
this.infoDanmakuApi = this.container.querySelector('.dplayer-info-panel-item-danmaku-api .dplayer-info-panel-item-data');
this.infoDanmakuAmount = this.container.querySelector('.dplayer-info-panel-item-danmaku-amount .dplayer-info-panel-item-data');
}

static NewNotice(text, opacity) {
const notice = document.createElement('div');
notice.classList.add('dplayer-notice');
notice.style.opacity = opacity;
notice.innerText = text;
return notice;
}
}

export default Template;
2 changes: 1 addition & 1 deletion src/template/player.art
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
</div>
{{ /each }}
</div>
<div class="dplayer-notice"></div>
<div class="dplayer-notice-list"></div>
<button class="dplayer-mobile-play">
{{@ icons.play }}
</button>

0 comments on commit 281334b

Please sign in to comment.