Skip to content

Commit

Permalink
feature: issues:#161 Add danmaku speed control
Browse files Browse the repository at this point in the history
  • Loading branch information
siegaii authored and DIYgod committed Aug 15, 2022
1 parent c162fcc commit 6d7d9f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/css/danmaku.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
transform: translateX(100%);
&.dplayer-danmaku-move {
will-change: transform;
animation: danmaku 5s linear;
animation-name: 'danmaku';
animation-timing-function: linear;
animation-play-state: paused;
}
}
Expand All @@ -41,7 +42,8 @@
visibility: hidden;
&.dplayer-danmaku-move {
will-change: visibility;
animation: danmaku-center 4s linear;
animation-name: 'danmaku-center';
animation-timing-function: linear;
animation-play-state: paused;
}
}
Expand Down
18 changes: 1 addition & 17 deletions src/css/player.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,7 @@
margin: 0;
padding: 0;
transform: translate(0, 0);

.dplayer-danmaku {
.dplayer-danmaku-top,
.dplayer-danmaku-bottom {
&.dplayer-danmaku-move {
animation: danmaku-center 6s linear;
animation-play-state: inherit;
}
}

.dplayer-danmaku-right {
&.dplayer-danmaku-move {
animation: danmaku 8s linear;
animation-play-state: inherit;
}
}
}

}

&.dplayer-no-danmaku {
Expand Down
17 changes: 17 additions & 0 deletions src/js/danmaku.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import utils from './utils';
class Danmaku {
constructor(options) {
this.options = options;
this.player = this.options.player;
this.container = this.options.container;
this.danTunnel = {
right: {},
Expand Down Expand Up @@ -254,6 +255,7 @@ class Danmaku {
if (tunnel >= 0) {
// move
item.classList.add('dplayer-danmaku-move');
item.style.animationDuration = this._danAnimation(dan[i].type);

// insert
docFragment.appendChild(item);
Expand Down Expand Up @@ -343,6 +345,21 @@ class Danmaku {
unlimit(boolean) {
this.unlimited = boolean;
}

speed(rate) {
this.options.api.speedRate = rate;
}

_danAnimation(position) {
const rate = this.options.api.speedRate || 1;
const isFullScreen = !!this.player.fullScreen.isFullScreen();
const animations = {
top: `${(isFullScreen ? 6 : 4) / rate}s`,
right: `${(isFullScreen ? 8 : 5) / rate}s`,
bottom: `${(isFullScreen ? 6 : 4) / rate}s`,
};
return animations[position];
}
}

export default Danmaku;
2 changes: 2 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class DPlayer {

if (this.options.danmaku) {
this.danmaku = new Danmaku({
player: this,
container: this.template.danmaku,
opacity: this.user.get('opacity'),
callback: () => {
Expand Down Expand Up @@ -106,6 +107,7 @@ class DPlayer {
maximum: this.options.danmaku.maximum,
addition: this.options.danmaku.addition,
user: this.options.danmaku.user,
speedRate: this.options.danmaku.speedRate,
},
events: this.events,
tran: (msg) => this.tran(msg),
Expand Down

1 comment on commit 6d7d9f3

@wdssmq
Copy link
Contributor

@wdssmq wdssmq commented on 6d7d9f3 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

animation-name 属性值并不能用引号。。

animation-name - CSS:层叠样式表 | MDN
https://developer.mozilla.org/zh-CN/docs/Web/CSS/animation-name

Please sign in to comment.