How to Make SlideShare Responsive With FitVid.js

Open Source software is awesome. If it weren’t for WordPress then I’m not sure what I would be doing – but that doesn’t mean open source software is perfect, or that it fulfills all requirements.

The beauty of open source software is that you can change it to match your requirements – or even to do things it wasn’t meant to do.

For instance – I recently added a SlideShare presentation about SEO to this site – and it bothered me that the presentation wasn’t responsive. Not being responsive meant it was sat in a weird size to one side of the page. It also meant that on narrower screens it didn’t scale nicely.

Fit Vid

Then I remembered FitVid.js. FitVid.js is a very simple JavaScript library that makes embedded videos (from sites like YouTube and Vimeo) responsive. It stretches them so that they fill 100% of the available space, and scales them with the browser. This functionality was exactly what I wanted for SlideShare. Even though Slideshare isn’t a video it’s embedded in the same way so I thought I would see if I could add SlideShare support.

And I can.

And it was easy 🙂

To resize the videos FitVid.js has a list of iframes and their source urls that it searches for to apply the sizing code to. All I had to do was add SlideShare.net to the list.

To do this I found this code:

var selectors = [
	"iframe[src*='player.vimeo.com']",
	"iframe[src*='youtube.com']",
	"iframe[src*='youtube-nocookie.com']",
	"iframe[src*='kickstarter.com'][src*='video.html']",
	"object",
	"embed"
];

and added iframe[src*='slideshare.net'] making:

var selectors = [
	"iframe[src*='player.vimeo.com']",
	"iframe[src*='youtube.com']",
	"iframe[src*='youtube-nocookie.com']",
	"iframe[src*='kickstarter.com'][src*='video.html']",
	"iframe[src*='slideshare.net']",
	"object",
	"embed"
];

More FitVid?

After making the change I found that there’s actually a second (possibly better) method for adding support for slideshare. It turns out FitVid has support for adding your own resizable videos (or presentations in this case).

All you have to do is pass the resize string as a parameter when initiating FitVid. Which for Slideshare looks like this:

$("#thing-with-videos").fitVids({ customSelector: "iframe[src^='www.slideshare.net']"});

I kept my modified version since I had already rewritten a lot of FitVid to remove things like inline styles – and to make it play better with jQuery.

Updated

I’ve now added support to my site for Prezi (because of this post about WordCamp EU) so here’s the updated ruleset.

var selectors = [
	"iframe[src*='player.vimeo.com']",
	"iframe[src*='youtube.com']",
	"iframe[src*='youtube-nocookie.com']",
	"iframe[src*='kickstarter.com'][src*='video.html']",
	"iframe[src*='slideshare.net']",
	"iframe[src*='prezi.com']",
	"object",
	"embed"
];

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
30 Mar 2010

10 WordPress query_posts tips you probably don’t know

I have written a really brief query_post tutorial before, and it did quite well, but both WordPress and my own skills, have advanced considerably since then. So I thought it would be interesting to revisit the query_posts command and see...
14 May 2013

Redesigning the WordPress Post Editor

Ghost is a project born from frustration with WordPress. Ironically it seems to be mostly WordPress power users who want to use it. The Ghost team – led by John O’Nolan – put Ghost on KickStarter last week and it...
30 Apr 2005

The Design One

I mentioned in my first post that I was going to do a run down of how I redesigned this site. It’s taken a while to put together but here it is.Binary Moon – a brief historyI started Binary Moon...
28 Aug 2009

Binary Moon WordPress design vIII

As I briefly mentioned on Monday, I have finally redesigned Binary Moon.I actually started redesigning about 2 years ago. Initially it was going to be an update rather than a totally new look, and I even built most of it,...
15 Oct 2013

My First WordCamp EU

Last weekend I went to WordCamp EU – Europe’s first WordCamp – and my first WordCamp.I’ve always fancied going to a WordCamp conference but never known what to expect – or even what I would get out of it. I’ve...