Skip to content

Instantly share code, notes, and snippets.

@6ui11em
Created December 11, 2013 17:46
Show Gist options
  • Save 6ui11em/7915070 to your computer and use it in GitHub Desktop.
Save 6ui11em/7915070 to your computer and use it in GitHub Desktop.
JQuery: vAlign middle
(function ($) {
$.fn.vAlign = function() {
return this.each(function(i){
var h = $(this).height();
var oh = $(this).outerHeight();
var mt = (h + (oh - h)) / 2;
$(this).css("margin-top", "-" + mt + "px");
$(this).css("top", "50%");
$(this).css("position", "absolute");
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment