Created
October 13, 2013 12:50
-
-
Save acarabott/6961987 to your computer and use it in GitHub Desktop.
Make embed codes responsive
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
.embed-wrap { | |
position: relative; | |
padding-top: 25px; /* IE6 workaround*/ | |
height: 0; | |
object, embed, iframe { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
} |
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
function resize_embed($embed) { | |
$embed_width_matches = array(); | |
$embed_height_matches = array(); | |
preg_match('/width=\"([0-9]+)\"/', $embed, $embed_width_matches); | |
preg_match('/height=\"([0-9]+)\"/', $embed, $embed_height_matches); | |
$embed_width = intval($embed_width_matches[1]); | |
$embed_height = intval($embed_height_matches[1]); | |
$pad_bot = intval(($embed_height / $embed_width) * 100); | |
$embed = preg_replace( | |
array('/width=\"[0-9]+\"/', '/height=\"[0-9]+\"/' ), | |
array('', ''), | |
$embed | |
); | |
return '<div class="embed-wrap" style="padding-bottom: ' . $pad_bot . '%">' . $embed . '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment