aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2006-08-13 14:51:02 +0000
committerJohn Resig <jeresig@gmail.com>2006-08-13 14:51:02 +0000
commitf3ac04e5937e95bb85520a2f81e8669fd4843ae8 (patch)
tree243b557dae6f6afad1cb94a86f68b02c888bd819
parenta42a8e5afa2e4ca7690081bce9899d5e6e0d1cf4 (diff)
downloadjquery-f3ac04e5937e95bb85520a2f81e8669fd4843ae8.tar.gz
jquery-f3ac04e5937e95bb85520a2f81e8669fd4843ae8.zip
Created the new plugins directory.
-rw-r--r--plugins/center/center.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/plugins/center/center.js b/plugins/center/center.js
new file mode 100644
index 000000000..81ef18787
--- /dev/null
+++ b/plugins/center/center.js
@@ -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";
+ }
+ });
+};