I believe what you want to do is set position: relative
on #content
. That way the position
is calculated in relation to the container instead of the overall page.
EDIT: After some clarification, you still need the position: relative
but you also need to add in the current scrollTop
value:
var top = dest.top + $('#content').scrollTop();