diff options
author | Trent Richardson <trentdrichardson@gmail.com> | 2014-10-13 12:06:26 -0400 |
---|---|---|
committer | Trent Richardson <trentdrichardson@gmail.com> | 2014-10-13 12:06:26 -0400 |
commit | 170e1cccf782bd20b1db64f9cf8588bfaa004d1f (patch) | |
tree | 3ae6104b730ef73b34314a7cedca0123224f0612 /src | |
parent | 38e29ee23b07363faa288de4d287f54c0055e291 (diff) | |
download | jQuery-Impromptu-170e1cccf782bd20b1db64f9cf8588bfaa004d1f.zip jQuery-Impromptu-170e1cccf782bd20b1db64f9cf8588bfaa004d1f.tar.gz jQuery-Impromptu-170e1cccf782bd20b1db64f9cf8588bfaa004d1f.tar.bz2 |
Adds offset util function
Diffstat (limited to 'src')
-rw-r--r-- | src/jquery-impromptu.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js index 6c36f9e..ad88a67 100644 --- a/src/jquery-impromptu.js +++ b/src/jquery-impromptu.js @@ -806,6 +806,22 @@ };
/**
+ * Sel.offset - get the offset of an element from the overall document x/y
+ * @return Object - {x: 123, y: 123} relative to the document, not the parent
+ */
+ Sel.prototype.offset = function(){
+ var el = this.nodes[0],
+ ret = { x:0, y:0 };
+
+ do {
+ ret.x += isNaN(el.offsetLeft) ? 0 : el.offsetLeft;
+ ret.y += isNaN(el.offsetTop) ? 0 : el.offsetTop;
+ } while(el = el.offsetParent);
+
+ return ret;
+ };
+
+ /**
* Sel.css - get/set the css properties on all nodes in collection
* @param data string, object - string of property name to get, a hash of key/values to set
* @return Class - returns this Sel class instance or value when using get
|