Skip to content

Commit

Permalink
scrollTo
Browse files Browse the repository at this point in the history
  • Loading branch information
blackout314 committed Jun 26, 2015
1 parent 4942ea9 commit 584d149
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pi.js",
"version": "0.3.0",
"version": "0.3.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
Expand Down
29 changes: 29 additions & 0 deletions src/pi.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ Element.prototype.on = Element.prototype.addEventListener;
* @example pi('#id').rm('click', callback)
*/
Element.prototype.rm = Element.prototype.removeEventListener;
/**
*
*/
Element.prototype.getPos = function () {
"use strict";
var elem = this,
box = elem.getBoundingClientRect(),
body = document.body,
docElem = document.documentElement,
scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop,
scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft,
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
top = box.top + scrollTop - clientTop,
left = box.left + scrollLeft - clientLeft;

return {
top: Math.round(top),
left: Math.round(left)
};
};
/**
*
*/
Element.prototype.scrollTo = function () {
"use strict";
var coords = this.getPos();
window.scrollTo(coords.left, coords.top);
};

NodeList.prototype.cycle = function (event, fn, action) {
"use strict";
Expand Down

0 comments on commit 584d149

Please sign in to comment.