Skip to content

Instantly share code, notes, and snippets.

@LeoSeyers
Last active March 1, 2023 13:14
Show Gist options
  • Save LeoSeyers/d5838dd13d9fba4791fe2b38037d1e33 to your computer and use it in GitHub Desktop.
Save LeoSeyers/d5838dd13d9fba4791fe2b38037d1e33 to your computer and use it in GitHub Desktop.
Vimeo Full Screen Video Background
.c-cover {
--height: 100dvh;
--safe-height: var(--height, var(--vh));
--container-width: 100vw;
--container-height: var(--safe-height);
position: relative;
height: var(--container-height);
overflow: hidden;
width: var(--container-width);
iframe {
/* [1] video width and height variables are inherited from inline styles */
--height-width-ratio: (var(--video-height) / var(--video-width)); // [1]
--width-height-ratio: (var(--video-width) / var(--video-height)); // [1]
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: var(--container-width);
height: calc(var(--container-width) * var(--height-width-ratio));
min-height: var(--container-height);
min-width: calc(var(--container-height) * var(--width-height-ratio));
}
}
@LeoSeyers
Copy link
Author

LeoSeyers commented Feb 10, 2023

Alternatively using Vimeo player SDK

 async setAspectRatio() {
    const promises = [
      this.player.getVideoWidth(),
      this.player.getVideoHeight(),
    ]
    const [width, height] = await Promise.all(promises)

    this.iframe.style.setProperty('--video-width', width)
    this.iframe.style.setProperty('--video-height', height)
  }

@LeoSeyers
Copy link
Author

To do : custom lite-vimeo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment