varemenos
7/2/2012 - 11:48 PM

JQuery - Vertically Center Div

JQuery - Vertically Center Div

$(document).ready(function(){
	$(window).resize(function(){
		var target = '#main';
		$(target).css({
			position:'absolute',
			left: ($(window).width() - $(target).outerWidth())/2,
			top: ($(window).height() - $(target).outerHeight())/2
		});
	});

	// To initially run the function:
	$(window).resize();
});