Created
May 1, 2014 06:42
-
-
Save arigesher/586c217e913b462ef0e5 to your computer and use it in GitHub Desktop.
embeddable javascript file that will dynamically resize the height on flickr embeds to remove all black space and fit them into the container.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var waitForJquery = function(dofn, interval) { | |
if(typeof $ === 'function') { | |
dofn(); | |
} else { | |
setTimeout(function() { | |
if(typeof $ === 'function'){ | |
dofn(); | |
} else { | |
waitForJquery(dofn, interval); | |
} | |
}, interval); | |
} | |
}; | |
waitForJquery(function() { | |
$(document).ready(function() { | |
$("div.flickrEmbeds iframe").each(function(index) { | |
var ratio = $(this).height() / $(this).width(); | |
var origHeight = $(this).height(); | |
var origWidth = $(this).width(); | |
var self = this; | |
$(window).resize(function() { | |
if($(self).parent().width() > origWidth) { | |
$(self).width(origWidth); | |
$(self).height(origHeight); | |
} else { | |
$(self).width($(self).parent().width()); | |
$(self).height($(self).parent().width() * ratio); | |
} | |
}); | |
}); | |
$(window).resize(); | |
}); | |
}, 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment