Skip to content

Commit

Permalink
update: observe container resize
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukumijima committed Jan 2, 2023
1 parent 6ebc025 commit 4b12f56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/css/player.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
}

&.dplayer-arrow {
&.dplayer-narrow {
.dplayer-danmaku {
font-size: 18px;
}
Expand Down
22 changes: 19 additions & 3 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,26 @@ class DPlayer {
if (utils.isMobile) {
this.container.classList.add('dplayer-mobile');
}
this.arrow = this.container.offsetWidth <= 500;
if (this.arrow) {
this.container.classList.add('dplayer-arrow');
this.narrow = this.container.offsetWidth <= 500;
if (this.narrow) {
this.container.classList.add('dplayer-narrow');
}

// observe container resize
this.resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.target === this.container) {
this.narrow = this.container.offsetWidth <= 500;
if (this.narrow) {
this.container.classList.add('dplayer-narrow');
} else {
this.container.classList.remove('dplayer-narrow');
}
}
}
});
this.resizeObserver.observe(this.container);

this.template = new Template({
container: this.container,
options: this.options,
Expand Down Expand Up @@ -1002,6 +1017,7 @@ class DPlayer {
this.video.src = '';
this.container.innerHTML = '';
this.events.trigger('destroy');
this.resizeObserver.disconnect();
}

static get version() {
Expand Down

0 comments on commit 4b12f56

Please sign in to comment.