Created
May 17, 2014 06:41
-
-
Save baniol/f64e99eb22ffe524a792 to your computer and use it in GitHub Desktop.
center box, jquery plugin
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
/** | |
* jQuery utility for centering a div on the screen | |
* | |
* @static | |
* @method $.centerBox | |
*/ | |
$.fn.centerBox = function () { | |
var t = this; | |
t.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px"); | |
t.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px"); | |
return t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment