Return to Snippet

Revision: 17062
at August 21, 2009 15:26 by publicbroadcast


Initial Code
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;  
}  
  
//Use the above function as:  
$(element).center();

Initial URL


Initial Description


Initial Title
Center something in jQuery

Initial Tags


Initial Language
jQuery