You can make it death-centered as follows:
$('#elementID').css({ position:'absolute', top:'50%', left:'50%', width:'600px', // adjust width height:'300px', // adjust height zIndex:1000, marginTop:'-150px' // half of height marginLeft:'-300px' // half of width });
Note that the item will appear in the center, but it will not move when scrolling. If you want it to appear in the center, you need to set position to fixed . However, this will not work in IE6. So your decision :)
You can also create a quick simple jQuery plugin:
(function($){ $.fn.centerIt = function(settings){ var opts = $.extend({}, $.fn.centerIt.defaults, settings); return this.each(function(settings){ var options = $.extend({}, opts, $(this).data()); var $this = $(this); $this.css({ position:options.position, top:'50%', left:'50%', width:options.width,
And later use it like:
$('#elementId').centerIt({width:'400px', height:'200px'});
source share