r/webdev • • Jul 25 '16
I made a 3kb library for making embedded videos responsive - doesn't require other libraries!
https://github.com/corbindavenport/superembed.js
253
Upvotes
r/webdev • • Jul 25 '16
18
u/[deleted] Jul 25 '16 edited Jul 25 '16
EDIT: There's now a JSFiddle.
SuperEmbed.js detects YouTube, Vimeo, Vine, VideoPress, DailyMotion, and more embedded videos on webpages and makes them responsive. Essentially, this means they strech to fill their container while still maintaining the original aspect ratio.
There's a lot of existing libraries that do this, but I had issues or just didn't like all the ones I tried, so I made my own. And this is it.
Features
calc()property if the browser supports it, so no messy injected DIV tags35
u/mtx Jul 25 '16
Why not use css? https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php
16
u/davesidious Jul 25 '16
It does require other libraries, they're just included in the source :)
4
u/ijustupvoteeverythin Jul 25 '16
Cool, but doesn't look like it respects aspect ratios other than 16:9?
Perhapd you should consider adding a data-aspect-ratio or something.
7
u/kevinkace Jul 25 '16 edited Jul 27 '16
Cool idea.
A suggestion would be to have
srcanddistfolders (for the source and compiled files), so you can move out Modernizer and the doc ready fns to separate files. Use browserify or something to bundle.Maybe break up the long css selectors so they are more readable such as
(line breaks aren't being preserved, imagine it's broken up...):1
u/notsure1235 Jul 25 '16
what is the difference between a responsive video and an unresponsive one?
1
u/webdevbrian Jul 25 '16
Only 16:9 without having to edit the lib?
edit: You embedded modernizer right into the library?
1
u/OrShUnderscore Jul 28 '16
hey, you made the meirl twitter bot!
1
u/MrQuickLine front-end Jul 25 '16
Vid.me please?
1
u/techgila Jul 25 '16
Very cool! I have a wordpress blog and test drove this. Worked fine!
1
u/[deleted] Jul 26 '16
Nice work!
But you should probably stop using XP at some point...
1
u/NORSE_ javascript 🔥 Jul 26 '16
var cool = Modernizer.cssCalc ? 'height: calc(100vw*(4/4.25))' : 'padding-bottom: 53%'There is ways to make it even smaller. Not sure i'd seek out something to do this for me as it's trivial but cool beans!
1
u/Ginden Jul 26 '16
Hm...
1
u/jml26 Jul 29 '16
The CSS
calc()code path assumes that the width of the video is always the width of the browser. What if it isn't?1
u/err4nt Oct 05 '16
I've got a little script that does the same thing for videos from Youtube or Vimeo with their default embed code: https://codepen.io/tomhodgins/pen/YyarJz?editors=0010
But I much prefer doing something like this:
There's a demo of that here: http://codepen.io/tomhodgins/pen/PZqaLm
1
u/TotesMessenger Jul 25 '16
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
0
u/[deleted] Jul 25 '16
[deleted] — view deleted comment
0
u/[deleted] Jul 25 '16
[deleted] — view deleted comment