Created
July 29, 2013 04:58
-
-
Save utsengar/6102220 to your computer and use it in GitHub Desktop.
Center any div on page (think google.com's search box)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $(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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment