centerElement
Description:
A jQuery plugin to position an element on the center of the screen.
The code:
(function($)
{
$.fn.centerElement = function() {
return this.each(function()
{
var el = this;
$(el).remove().appendTo("body")
.wrap("<div style='position:absolute;top:50%;left:50%;width:1px;height:1px;'></div>")
.css({position: 'relative', left: el.offsetWidth / -2 + "px", top: el.offsetHeight / -2 + "px"});
});
};
})(jQuery);
License:
The plugin is available under both MIT and GPL licenses (as jQuery itself). This means that you can choose the license that best suits your project, and use it accordingly.
The plugin was successfully tested on Firefox 2, Opera 9.10 and IE 6.