I had a similar problem. I made slide shows with various objects in the form of slides, some of them are videos of different sizes. I did not find a conceptual solution, so I found a trick.
I clearly indicated all the real sizes of the video in the tags and collected information about all of them:
var vids = document.getElementsByClassName("vid"); // videos var vidl = vids.length; var vidH = [ ]; var vidW = [ ]; // Get original widths and heights of videos for (i=0; i<vidl; i++) { // > vidH.push(vids[i].height); vidW.push(vids[i].width); }
Then (if necessary) I determine the size of the window as follows:
// Current inner height of the browser window (in pixels) var iH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; // Current inner width of the browser window (in pixels) var iW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
To recolor a rectangle into another rectangle, we need to find the minimum scale:
var r, rh, rw; // Scale videos to fit window for (i=0; i<vidl; i++) { // > rh=iH / vidH[i]; rw=iW / vidW[i]; r=Math.min(rh, rw); if (rh>rw) { vids[i].height=Math.floor(vidH[i]*r); vids[i].width=iW; } else { vids[i].height=iH-5; vids[i].width=Math.floor(vidW[i]*r); } }
Unfortunately, some additional space has appeared here; in FireFox I found my minimum value as 5, that I deny the window height (iH) value as the new video size.
source share