Skip to content

Instantly share code, notes, and snippets.

@samrayner
Last active August 29, 2015 13:56
Show Gist options
  • Save samrayner/9293377 to your computer and use it in GitHub Desktop.
Save samrayner/9293377 to your computer and use it in GitHub Desktop.
class FluidVideos
@init: (container=null, $videos=null) ->
$videos ||= $("iframe[src*='vimeo.com'], iframe[src*='youtube.com']")
$videos.each ->
$(this)
.data('aspectRatio', this.height/this.width)
.removeAttr('height')
.removeAttr('width')
$(window).resize ->
$videos.each ->
$elm = $(this)
$parent = if container then $(container) else $elm.parent()
newWidth = $parent.width()
$elm
.width(newWidth)
.height(newWidth * $elm.data('aspectRatio'))
$(window).resize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment