Monday, 18 February 2013

Center an element on the screen using jQuery



    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;
}

 This is how you use it:  $('#window').center();

The above method will show the control @ center of the Window.

No comments:

Post a Comment