How to determine exact position of a dom element regardless of scrolling

I need the bounds of a dom element and use it by shrinking a little, here’s my code:

var rack = $('.rack')[0];
var rackBounds = rack.getBoundingClientRect();

rackBounds = {
  top: rack.offsetTop + 10
  left: rack.offsetLeft + 10
  height: rackBounds.height - 10
  width: rackBounds.width - 10
};

When I use this it works fine, but if I scroll the page to bottom, this fails, why


Source: New Questions

Leave a Reply