Created
November 9, 2014 06:07
-
-
Save Stasevi4/957b8fbcbca4c7b283f0 to your computer and use it in GitHub Desktop.
Vertical Align of element jQuery
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 ($) { | |
// VERTICALLY ALIGN FUNCTION | |
$.fn.vAlign = 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment