Alternative approaches
Rather than directly accessing a specific div and its pixel offset, you can also access some related values from CodeMirror (Which is the framework that Obsidian uses for its editor).
This would be safer as it wouldn’t break if Obsidian changed its Html structure in the future.
It may work for what you need, but I abandoned this approach as it only provides the ability to know the number of lines that have been scrolled, or the fraction of a partially visible line.
Before abandoning it, my first thought was that I could get the scrollY in pixels by using an equation like below:
scrollFraction = (numberOfLines + remainderFraction) / totalLines;
scrollY = pageHeightPx * scrollFraction;
However, I quickly realised that line heights can differ in Obsidian depending on whether the line was a heading or even some other form of embed (perhaps even replaced by a plugin).
There may well be ways to get these correctly, but at this point it felt unnecessarily complicated and potentially becoming delicate in itself. So I didn’t pursue this further and used the solution noted above.
If you‘re interested in pursuing the lines alternative, here’s the code I started with:
const markdownView = plugin.app.workspace.getActiveViewOfType(MarkdownView);
// I wouldn't recommend using setInterval, but it’s what I used for testing.
let scrollCheckInterval = setInterval( () => {
const scroll = markdownView.currentMode.getScroll();
console.log('scroll', scroll);
}, 1000);