Skip to content

Instantly share code, notes, and snippets.

@utsengar
Created July 29, 2013 04:58

Revisions

  1. utsengar created this gist Jul 29, 2013.
    8 changes: 8 additions & 0 deletions center_div.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // $(element).center();
    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;
    }