Return to Snippet

Revision: 40355
at January 31, 2011 15:27 by greenconure


Initial Code
jQuery.fn.centerx = function () {
			    this.css("position","absolute");
			    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
			    return this;
			}
			
			jQuery.fn.center = function () {
			    this.css("position","absolute");
			    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
			    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
			    return this;
			}
			
			$(function(){
				$("#header").centerx();
				$("#dropzone, #browser").center();
			});
			$(window).resize(function(){
				$("#header").centerx();
				$("#dropzone, #browser").center();
			});

Initial URL
http://general-metrics.com/

Initial Description
I like how this site uses jQuery to center some elements and I wanted to save the code incase they change their site ever.

Initial Title
Simple element centering with jQuery

Initial Tags
jquery

Initial Language
JavaScript