/***
@title:
Center
@version:
2.0
@author:
Andreas Lagerkvist
@date:
2008-09-17
@url:
http://andreaslagerkvist.com/jquery/center/
@license:
http://creativecommons.org/licenses/by/3.0/
@copyright:
2008 Andreas Lagerkvist (andreaslagerkvist.com)
@requires:
jquery
@does:
This little pluggy centers an element on the screen using either fixed or absolute positioning. Can be used to display messages, pop up images etc.
***/
jQuery.fn.center = function (absolute) { return this.each(function () { var t = jQuery(this); t.css({ position: absolute ? 'absolute' : 'fixed', left: '50%', top: '50%' }).css({ marginLeft: '-' + (t.outerWidth() / 2) + 'px', marginTop: '-' + (t.outerHeight() / 2) + 'px' }); if (absolute) { t.css({ marginTop: parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft() }); } });};
