Created
December 11, 2013 17:46
-
-
Save 6ui11em/7915070 to your computer and use it in GitHub Desktop.
JQuery: vAlign middle
This file contains hidden or 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 ($) { | |
$.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