mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Created the new plugins directory.
This commit is contained in:
parent
a42a8e5afa
commit
f3ac04e593
26
plugins/center/center.js
Normal file
26
plugins/center/center.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Takes all matched elements and centers them, absolutely,
|
||||||
|
* within the context of their parent element. Great for
|
||||||
|
* doing slideshows.
|
||||||
|
* $("div img").center();
|
||||||
|
*/
|
||||||
|
$.fn.center = function(f) {
|
||||||
|
return this.each(function(){
|
||||||
|
if ( !f && this.nodeName == 'IMG' &&
|
||||||
|
!this.offsetWidth && !this.offsetHeight ) {
|
||||||
|
var self = this;
|
||||||
|
setTimeout(function(){
|
||||||
|
$(self).center(true);
|
||||||
|
}, 13);
|
||||||
|
} else {
|
||||||
|
var s = this.style;
|
||||||
|
var p = this.parentNode;
|
||||||
|
if ( $.css(p,"position") == 'static' ) {
|
||||||
|
p.style.position = 'relative';
|
||||||
|
}
|
||||||
|
s.position = 'absolute';
|
||||||
|
s.left = (($.css(p,"width") - $.css(this,"width"))/2) + "px";
|
||||||
|
s.top = (($.css(p,"height") - $.css(this,"height"))/2) + "px";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user