WordPress Snippet
Last active
February 28, 2018 18:00
-
-
Save ControlledChaos/5706c0efdfc1654b1acc065dc8533eee to your computer and use it in GitHub Desktop.
Makes the video embeds in Wordpress posts 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
.wp-video, video.wp-video-shortcode, .mejs-container, .mejs-overlay.load { | |
width: 100% !important; | |
height: 100% !important; | |
} | |
.mejs-container { | |
padding-top: 56.25%; | |
} | |
.wp-video, video.wp-video-shortcode { | |
max-width: 100% !important; | |
} | |
video.wp-video-shortcode { | |
position: relative; | |
} | |
.mejs-mediaelement { | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
} | |
.mejs-controls { | |
display: none; | |
} | |
.mejs-overlay-play { | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
width: auto !important; | |
height: auto !important; | |
} |
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
jQuery(document).ready(function () { | |
jQuery(function () { | |
jQuery('.mejs-overlay-loading').closest('.mejs-overlay').addClass('load'); //just a helper class | |
var $video = jQuery('div.video video'); | |
var vidWidth = $video.attr('width'); | |
var vidHeight = $video.attr('height'); | |
jQuery(window).resize(function () { | |
var targetWidth = jQuery(this).width(); //using window width here will proportion the video to be full screen; adjust as needed | |
jQuery('div.video, div.video .mejs-container').css('height', Math.ceil(vidHeight * (targetWidth / vidWidth))); | |
}).resize(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment