<div id="page" class="site"> <div class="header-wrapper"> <div class='header-homepage color-overlay cp-video-bg' style='; min-height:100vh'> <div class="background-overlay"></div> <script> // resize the poster image as fast as possible to a 16:9 visible ratio var mesmerize_video_background = { getVideoRect: function () { var header = document.querySelector(".cp-video-bg"); var headerWidth = header.getBoundingClientRect().width, videoWidth = headerWidth, videoHeight = header.getBoundingClientRect().height; videoWidth = Math.max(videoWidth, videoHeight); if (videoWidth < videoHeight * 16 / 9) { videoWidth = 16 / 9 * videoHeight; } else { videoHeight = videoWidth * 9 / 16; } videoWidth *= 1.2; videoHeight *= 1.2; var marginLeft = -0.5 * (videoWidth - headerWidth); return { width: Math.round(videoWidth), height: Math.round(videoHeight), left: Math.round(marginLeft) } }, resizePoster: function () { // debugger; var posterHolder = document.querySelector('#wp-custom-header'); var size = mesmerize_video_background.getVideoRect(); posterHolder.style.backgroundSize = size.width + 'px auto'; posterHolder.style.backgroundPositionX = size.left + 'px'; posterHolder.style.minHeight = size.height + 'px';