Last active
July 18, 2022 11:03
Revisions
-
jlong revised this gist
Jul 21, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,9 @@ function getViewportOffset(element) { top -= node.scrollTop; if (/relative|absolute|fixed/.test(position)) { left += parseInt(styles.getPropertyValue('border-left-width'), 10); top += parseInt(styles.getPropertyValue('border-top-width'), 10); left += node.offsetLeft; top += node.offsetTop; } -
jlong revised this gist
Jul 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function getViewportOffset(element) { var node = element , left = node.offsetLeft , top = node.offsetTop -
jlong created this gist
Jul 18, 2014 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ function getOffset(element) { var node = element , left = node.offsetLeft , top = node.offsetTop ; node = node.parentNode; do { var styles = getComputedStyle(node); if (styles) { var position = styles.getPropertyValue('position'); left -= node.scrollLeft; top -= node.scrollTop; if (/relative|absolute|fixed/.test(position)) { left += node.offsetLeft; top += node.offsetTop; } node = position === 'fixed' ? null : node.parentNode; } else { node = node.parentNode; } } while (node); return { left: left, top: top }; }