Skip to content

Instantly share code, notes, and snippets.

@matharchod
Created January 10, 2012 23:14
Show Gist options
  • Save matharchod/1591825 to your computer and use it in GitHub Desktop.
Save matharchod/1591825 to your computer and use it in GitHub Desktop.
A jQuery script for vertical centering
function vcenter(a, b) {
var wHeight = $(window).height();
var fHeight = $(a).height();
var nHeight = (wHeight / 2) - (fHeight);
if (!b || b == "" || b == null) {
var b = a;
}
$(b).css({
'position' : 'relative',
'top' : nHeight
});
}
$(window).ready( function () {
vcenter('#main');
}).resize( function () {
vcenter('#main');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment