Last active
October 26, 2020 08:20
-
-
Save arigesher/8932051 to your computer and use it in GitHub Desktop.
JQuery code to make Flickr embeds responsive (and resize correctly when loading in a mobile browser). See http://ari.gesher.net/photos-the-gesher-world-tour/ for a working example.
This file contains hidden or 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
$(document).ready(function() { | |
$("#pics iframe").each(function(index) { | |
var ratio = $(this).height() / $(this).width(); | |
var origHeight = $(this).height(); | |
var origWidth = $(this).width(); | |
var self = this; | |
// bind to window with closure that references the | |
// iframe since the iframe doesn't get resize events | |
// until (you know) we resize it. | |
$(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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment