Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function ($) {
$.fn.verticalAlign = function() {
return this.each(function(i){
var ah = $(this).height();
var ph = $(this).parent().height();
var mh = Math.ceil((ph-ah) / 2);
$(this).css('margin-top', mh);
});
};
})(jQuery);
jQuery(document).ready(function($){
// If the size of the parent item depends on images loading we
// need to fire after the page has loaded, that way the elements
// size is finalized, giving us the correct information.
// Use https://github.com/desandro/imagesloaded
$('#container').imagesLoaded( function() {
$(".caption").verticalAlign();
});
$( window ).resize(function() {
$(".caption").verticalAlign();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment