1var parentPos = document.getElementById('parent-id').getBoundingClientRect(),
2 childPos = document.getElementById('child-id').getBoundingClientRect(),
3 relativePos = {};
4
5relativePos.top = childPos.top - parentPos.top,
6relativePos.right = childPos.right - parentPos.right,
7relativePos.bottom = childPos.bottom - parentPos.bottom,
8relativePos.left = childPos.left - parentPos.left;
9
10console.log(relativePos);
11// something like: {top: 50, right: -100, bottom: -50, left: 100}