2 * Takes all matched elements and centers them, absolutely,
3 * within the context of their parent element. Great for
5 * $("div img").center();
7 $.fn.center = function(f) {
8 return this.each(function(){
9 if ( !f && this.nodeName == 'IMG' &&
10 !this.offsetWidth && !this.offsetHeight ) {
12 setTimeout(function(){
17 var p = this.parentNode;
18 if ( $.css(p,"position") == 'static' ) {
19 p.style.position = 'relative';
21 s.position = 'absolute';
22 s.left = (($.css(p,"width") - $.css(this,"width"))/2) + "px";
23 s.top = (($.css(p,"height") - $.css(this,"height"))/2) + "px";