Created
December 13, 2013 10:42
-
-
Save puneetkay/7942567 to your computer and use it in GitHub Desktop.
Small jQuery plugin for center of parent or window! (Tweaked to set margin instead of position)
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(parent) { | |
if (parent) { | |
parent = $(this).parent(); | |
} else { | |
parent = window; | |
} | |
$(this).css({ | |
"margin-top": ((($(parent).height() - $(this).outerHeight()) / 2) + $(parent).scrollTop() + "px"), | |
"margin-left": ((($(parent).width() - $(this).outerWidth()) / 2) + $(parent).scrollLeft() + "px") | |
}); | |
return $(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment