aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plugins/preview-thumbnails.js
diff options
context:
space:
mode:
authorShravan Rajinikanth <mail@shrav.me>2020-01-19 06:05:12 -0800
committerShravan Rajinikanth <mail@shrav.me>2020-01-19 06:05:12 -0800
commitbfcb7133cb682e801a4b46003853b3aa631afbbb (patch)
tree30bdf43bca756b8a4860b60c2bb81969fc32b40e /src/js/plugins/preview-thumbnails.js
parenta77d2d56f67d6b601940d89bd8ac9831e0949963 (diff)
downloadplyr-bfcb7133cb682e801a4b46003853b3aa631afbbb.tar.lz
plyr-bfcb7133cb682e801a4b46003853b3aa631afbbb.tar.xz
plyr-bfcb7133cb682e801a4b46003853b3aa631afbbb.zip
Fixed Plyr container not resizing responsively
Diffstat (limited to 'src/js/plugins/preview-thumbnails.js')
-rw-r--r--src/js/plugins/preview-thumbnails.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/js/plugins/preview-thumbnails.js b/src/js/plugins/preview-thumbnails.js
index 61021d64..930c055d 100644
--- a/src/js/plugins/preview-thumbnails.js
+++ b/src/js/plugins/preview-thumbnails.js
@@ -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);
@@ -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
@@ -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;