Last active
June 5, 2018 14:51
-
-
Save luislobo14rap/7afaaf7197b5f2bd928f7b9cb105815a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error in mac safari...