Get document / scroll height

I am trying to obtain total document/scroll height in pixels after the doc has been loaded. I’m using:




Both are “quite accurate” but the value changes slightly after the doc is scrolled up or down. When whole document has been scrolled from top to bottom, the value stays fixed (and accurate). How can I get accurate document height right after document has been loaded.

(I’m using scroll past end addon if this is somehow connected to the problem)


I presume - as only viewport is rendered the initial doc height is calculated based on normal line height; and I have lines with different heights in the doc, thus the initial error …

What is the best (fastest) way to get exact value at document load time?


You could (temporarily) set the viewportMargin option to Infinity, but that will be expensive if your document is big. The recommended approach is to just accept the fact that these are approximations, and recompute whatever you need to recompute when they change (by listening, for example, to the "viewportChange" event).