Skip to content

Commit

Permalink
Merge pull request #1651 from shravan2x/develop
Browse files Browse the repository at this point in the history
Fixed Plyr container not resizing responsively
  • Loading branch information
sampotts authored Jan 21, 2020
2 parents a77d2d5 + bfcb713 commit b6d94e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
29 changes: 22 additions & 7 deletions src/js/plugins/preview-thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ class PreviewThumbnails {

get thumbContainerHeight() {
if (this.mouseDown) {
// Can't use media.clientHeight - HTML5 video goes big and does black bars above and below
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio);
const { height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight });
return height;
}

return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4);
Expand Down Expand Up @@ -624,9 +624,9 @@ class PreviewThumbnails {

// Can't use 100% width, in case the video is a different aspect ratio to the video container
setScrubbingContainerSize() {
this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`;
// Can't use media.clientHeight - html5 video goes big and does black bars above and below
this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`;
const { width, height } = fitRatio(this.thumbAspectRatio, { width: this.player.media.clientWidth, height: this.player.media.clientHeight });
this.elements.scrubbing.container.style.width = `${width}px`;
this.elements.scrubbing.container.style.height = `${height}px`;
}

// Sprites need to be offset to the correct location
Expand All @@ -639,14 +639,29 @@ class PreviewThumbnails {
const multiplier = this.thumbContainerHeight / frame.h;

// eslint-disable-next-line no-param-reassign
previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`;
previewImage.style.height = `${previewImage.naturalHeight * multiplier}px`;
// eslint-disable-next-line no-param-reassign
previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`;
previewImage.style.width = `${previewImage.naturalWidth * multiplier}px`;
// eslint-disable-next-line no-param-reassign
previewImage.style.left = `-${frame.x * multiplier}px`;
// eslint-disable-next-line no-param-reassign
previewImage.style.top = `-${frame.y * multiplier}px`;
}

fitRatio(ratio, outer) {
const targetRatio = outer.width / outer.height;

const result = {};
if (ratio > targetRatio) {
result.width = outer.width;
result.height = (1 / ratio) * outer.width;
} else {
result.height = outer.height;
result.width = ratio * outer.height;
}

return result;
}
}

export default PreviewThumbnails;
3 changes: 2 additions & 1 deletion src/sass/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
font-family: $plyr-font-family;
font-variant-numeric: tabular-nums; // Force monosace-esque number widths
font-weight: $plyr-font-weight-regular;
height: 100%;
line-height: $plyr-line-height;
max-width: 100%;
min-width: 200px;
Expand All @@ -21,7 +22,7 @@
video,
audio {
border-radius: inherit;
height: auto;
height: 100%;
vertical-align: middle;
width: 100%;
}
Expand Down
1 change: 1 addition & 0 deletions src/sass/components/video.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.plyr__video-wrapper {
background: #000;
border-radius: inherit;
height: 100%;
overflow: hidden;
position: relative;
// Require z-index to force border-radius
Expand Down

0 comments on commit b6d94e0

Please sign in to comment.