Update danmuku.js

This commit is contained in:
Harvey committed 2022-05-05 14:25:55 +08:00
1 parent 288e29af3a
commit d8b4479f5d
1 file changed
+9 -10
@@ -72,16 +72,16 @@ export default class Danmuku {
get marginTop() { get marginTop() {
const { clamp } = this.utils; const { clamp } = this.utils;
const { $player } = this.art.template;
const value = this.option.margin[0]; const value = this.option.margin[0];
const { clientHeight } = this.$player;
if (typeof value === 'number') { if (typeof value === 'number') {
return clamp(value, 0, $player.clientHeight); return clamp(value, 0, clientHeight);
} }
if (typeof value === 'string' && value.endsWith('%')) { if (typeof value === 'string' && value.endsWith('%')) {
const ratio = parseFloat(value) / 100; const ratio = parseFloat(value) / 100;
return clamp($player.clientHeight * ratio, 0, $player.clientHeight); return clamp(clientHeight * ratio, 0, clientHeight);
} }
return Danmuku.option.margin[0]; return Danmuku.option.margin[0];
@@ -89,16 +89,16 @@ export default class Danmuku {
get marginBottom() { get marginBottom() {
const { clamp } = this.utils; const { clamp } = this.utils;
const { $player } = this.art.template;
const value = this.option.margin[1]; const value = this.option.margin[1];
const { clientHeight } = this.$player;
if (typeof value === 'number') { if (typeof value === 'number') {
return clamp(value, 0, $player.clientHeight); return clamp(value, 0, clientHeight);
} }
if (typeof value === 'string' && value.endsWith('%')) { if (typeof value === 'string' && value.endsWith('%')) {
const ratio = parseFloat(value) / 100; const ratio = parseFloat(value) / 100;
return clamp($player.clientHeight * ratio, 0, $player.clientHeight); return clamp(clientHeight * ratio, 0, clientHeight);
} }
return Danmuku.option.margin[1]; return Danmuku.option.margin[1];
@@ -295,8 +295,6 @@ export default class Danmuku {
} }
update() { update() {
const { clientWidth } = this.$player;
this.timer = window.requestAnimationFrame(async () => { this.timer = window.requestAnimationFrame(async () => {
if (this.art.playing && !this.isHide) { if (this.art.playing && !this.isHide) {
this.filter('emit', (danmu) => { this.filter('emit', (danmu) => {
@@ -309,6 +307,7 @@ export default class Danmuku {
}); });
const readys = this.getReady(); const readys = this.getReady();
const { clientWidth, clientHeight } = this.$player;
for (let index = 0; index < readys.length; index++) { for (let index = 0; index < readys.length; index++) {
const danmu = readys[index]; const danmu = readys[index];
danmu.$ref = this.getRef(); danmu.$ref = this.getRef();
@@ -338,8 +337,8 @@ export default class Danmuku {
target, target,
emits: this.getEmits(), emits: this.getEmits(),
antiOverlap: this.option.antiOverlap, antiOverlap: this.option.antiOverlap,
clientWidth: this.$player.clientWidth, clientWidth: clientWidth,
clientHeight: this.$player.clientHeight, clientHeight: clientHeight,
marginBottom: this.marginBottom, marginBottom: this.marginBottom,
marginTop: this.marginTop, marginTop: this.marginTop,
}); });