I have a scrollable element inside a window.
Say the section with the class "currentContainer" with automatic overflow, and this separation contains a huge amount of text, so it is definitely large enough to scroll.
Now I need to do some calculations based on how much the "currentContainer" scrolls + what is the offset of a specific element from its parent scroll div (that is, "currentCoantainer").
But when calculating the offset, I always get the offset of the inner child relative to the window, not with "currentContainer".
JS FIDDLE
@Shikkediel I also tried using position().top instead of offset().top , but also gives the same result. Look at this:
JS FIDDLE 2
Please do not offer to use:
$("<reference of scrolling element").scrollTop() + $("<reference of child element whose offset I want to calculate>").offset().top
Because it will complicate my actual calculations, which I am going to do outside of this.
The reason I don't want to use the above approach is because I am trying to modify existing code that is already too messy but works fine with respect to the window. I just need to update it so that it starts working on its parent scroll div.
I tried to use the above approach, but he opened for me a box of crabs. because the functions are too tightly coupled. Therefore, I think that if I can get a simple and direct solution, that is, replace .offset().top with something else.
I tried debugging the code and still no luck, I added the actual code to http://jsfiddle.net/arpitajain/kwkm7com/
PS This is actual code, but not complete. I think the rest of the code is not needed for this error.