Skip to content

Instantly share code, notes, and snippets.

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);
// 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
$('#container').imagesLoaded( function() {
$( window ).resize(function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment