Created
August 14, 2012 05:33
-
-
Save d33pfri3d/3346618 to your computer and use it in GitHub Desktop.
Jquery Center Function
This file contains hidden or 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.fn.center = function() { | |
_TOP = (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop(); | |
_TOP = (_TOP <= 0) ? 0 : _TOP; | |
_LEFT= (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft(); | |
_LEFT = (_LEFT <= 0) ? 0 : _LEFT; | |
this.css({ | |
top:_TOP + "px", | |
left:_LEFT + "px" | |
}); | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment