I’m running an HTML5 video on my page and I’d like to make it resize edge to edge in ratio based on the browser’s size. It will be set as a background with very little on the page.
To cover my ass, I’m using VideoJS to play the video and handle backwards compatibility. The fullscreen function built into the library works well, but is triggering the browser’s native fullscreen function. In some browsers this means black bars, in Safari it means literally fullscreen independent of the browser window. I don’t want either of these.
Ideally, it would function like Supersized does for images. The image is always set to the full width of the page, and height is cropped towards the CENTER from there. As you resize the page smaller and smaller, it hits a min-height and begins cropping the width towards the center.
My JavaScript knowledge is minimal, but I’m able to poke and prod to figure things out. I figured that dropping in the Supersized resizing scripts after the VideoJS library and forcing them to work on video tags would work in some way.. at least a starting place, but it didn’t work.
Can someone help me understand what function can adjust width to the page, height in ratio, and crop towards the center at a certain width or height? Here’s what I’ve got so far:
This is a tuffie, I know. Thank you SO much.
You can try the following, (based on the demo you posted)
add the class .fullScreen at the video-js-box and see what happens.
I am trying to achieve the effect you described above, and I ‘ll let you know as soon as I find a better solution.
EDIT: Ok I think I found a solution – (VERSION 2)
Copy – paste the above code to a new file and test it : )
MAJOR EDIT 2: I refactored my code, and packaged it in a more object oriented form. Now it does move (modified top and left css attributes) so that the video remains centered when the screen ratio changes. It still does a weird little jump but it works quite well.
I will keep working on this task because I think it’s a cool feature. Also I have no idea what happens or what would you like to happen during the flash fallback.
ps. I kept the click me button but it is very easy to disable it.