Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active May 11, 2018 03:13
Show Gist options
  • Save lenivene/16590265a70e6b6487fac91f393735dc to your computer and use it in GitHub Desktop.
Save lenivene/16590265a70e6b6487fac91f393735dc to your computer and use it in GitHub Desktop.
Identical jQuery offset() Method

#Example#

var element = document.getElementsByClassName("Your-Class-Here");
    element = ( ! element[0] ) ? element : element[0];

console.log( getOffset( element ) );
function getOffset( element ){
var rect = element.getBoundingClientRect();
return {
top: rect.top + window.pageYOffset,
left: rect.left + window.pageXOffset,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment