This commit is contained in:
Harvey Zack committed 2022-05-01 15:02:30 +08:00
1 parent 617ac9e893
commit 14c1240671
3 files changed
+37 -71

No files matched your search

@@ -255,7 +255,7 @@ class Danmuku {
const rect = $ref.getBoundingClientRect();
return this.isRotate ? rect.top : rect.left;
}
getDanmuRef() {
getRef() {
const result = this.queue.find((danmu)=>{
return danmu.$ref && danmu.$state === 'wait';
});
@@ -309,6 +309,18 @@ class Danmuku {
this.art.emit('artplayerPluginDanmuku:config', this.option);
return this;
}
makeWait(danmu) {
danmu.$state = 'wait';
if (danmu.$ref) {
danmu.$ref.dataset.state = 'wait';
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.left = `${this.$player.clientWidth}px`;
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
}
continue() {
const { clientWidth } = this.$player;
this.filter('stop', (danmu)=>{
@@ -349,32 +361,12 @@ class Danmuku {
return this;
}
resize() {
const { clientWidth } = this.$player;
this.queue.forEach((danmu)=>{
if (danmu.$ref) {
danmu.$ref.style.border = 'none';
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.left = `${clientWidth}px`;
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
});
console.log('resize');
return this;
}
reset() {
const { clientWidth } = this.$player;
this.filter('emit', (danmu)=>{
if (danmu.$ref) {
danmu.$state = 'wait';
danmu.$ref.dataset.state = 'wait';
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.left = `${clientWidth}px`;
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
});
this.queue.forEach((danmu)=>this.makeWait(danmu)
);
}
update() {
const { clientWidth } = this.$player;
@@ -385,20 +377,11 @@ class Danmuku {
danmu.$emitTime += time;
danmu.$restTime -= time;
danmu.$lastStartTime = Date.now();
if (danmu.$restTime <= 0) {
danmu.$state = 'wait';
danmu.$ref.dataset.state = 'wait';
danmu.$ref.style.border = 'none';
danmu.$ref.style.visibility = 'hidden';
danmu.$ref.style.marginLeft = '0px';
danmu.$ref.style.left = `${clientWidth}px`;
danmu.$ref.style.transform = 'translateX(0px) translateY(0px) translateZ(0px)';
danmu.$ref.style.transition = 'transform 0s linear 0s';
}
if (danmu.$restTime <= 0) this.makeWait(danmu);
});
this.queue.filter((danmu)=>this.art.currentTime + 0.1 >= danmu.time && danmu.time >= this.art.currentTime - 0.1 && danmu.$state === 'wait'
).forEach((danmu)=>{
danmu.$ref = this.getDanmuRef(this.queue);
danmu.$ref = this.getRef(this.queue);
this.$danmuku.appendChild(danmu.$ref);
danmu.$ref.style.visibility = 'visible';
danmu.$ref.style.opacity = this.option.opacity;