Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active June 5, 2018 14:51
Show Gist options
  • Save luislobo14rap/7afaaf7197b5f2bd928f7b9cb105815a to your computer and use it in GitHub Desktop.
Save luislobo14rap/7afaaf7197b5f2bd928f7b9cb105815a to your computer and use it in GitHub Desktop.
function offset(element, diffInTop, diffInLeft){
return element.offset(diffInTop, diffInLeft);
};
Object.prototype.offset = function(element, diffInTop, diffInLeft){
if( typeof diffInLeft == 'undefined' ){diffInLeft = 0;};
if( typeof diffInTop == 'undefined' ){diffInTop = 0;};
if( typeof element == 'undefined' ){element = 0;};
if( this != window ){
diffInLeft = diffInTop;
diffInTop = element;
element = this;
};
rectElement = element.getBoundingClientRect();
rectHtml = document.querySelector('html').getBoundingClientRect();
return {
top: rectElement.top + Math.abs(rectHtml.top) + diffInTop,
left: rectElement.left + Math.abs(rectHtml.left) + diffInLeft
};
};
@luislobo14rap
Copy link
Author

error in mac safari...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment