I have an 8MB video set to "object-fit:contain" and need to retrieve its height before it finishes loading on mobile devices. Reason I need the height earlier is to position content overlaying the video by matching the video height on this content container.
I am not looking for the actual height of the video, but the height as rendered in the user’s browser / viewport.
If I try to get the height while it’s loading, I get a much smaller value (200 some pixels) than what it ends up being (usually 600 some pixels). I’ve been able to get the height AFTER it loads using the load() function, but this method is very slow because my video is 8MB in size.
Is there any workaround?
jQuery(document).ready(function($){
function vidHeight() {
var newHeight = jQuery('#section-feature-device video').height();
jQuery(".elementor-element-0113321").css("height", newHeight+"px");
}
jQuery(window).load(function () {
var win = jQuery(this);
if (win.width() <= 767) {
vidHeight();
}
});
});
2
Answers
I found how to find the video height by knowing the video width was 100%, therefore I just multiply the viewport width by the aspect ratio of the video.
If you are planing to get the intrinsic height of the video, you may use the event listener loadedmetadata.