The plugins site is currently in development.
We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.
jQuery centerXY Plugin
jQuery centerXY Plugin
$.centerXY() will center an element within its parent. If the parent is the body, then it will be centered with regards to the window. It also binds to window.onresize, to make sure the element stays centered if the user changes the size of their window. You may specify an offset if you don't want the element perfectly centered.
One caveat is that it's best to have the element's height and width (and those of its parent) defined in CSS before you call the plugin. jQuery recommends this approach with CSS anyhow.
Usage:
$( elem ).centerXY( [offsetX], [offsetY] )
For offsetX and offsetY, positive numbers will move the element down and to the right.
Example:
$(document).ready(function(){
$('#content').centerXY();
});Example moved down and right 5 pixels:
$(document).ready(function(){
$('#content').centerXY(5,5);
});