Detect when a user arrives at the end of a readonly textarea in an html page
I need to detect when a user arrives at the end of a readonly textarea in an html page.
The textarea will display a very long log for an application. The logs files are so big that is impossible to load all the text in one time (some log files are almost 200 MB). So I will load the 开发者_高级运维first, say, 1000 lines, and then I need to detect when the user is near the last line of the loaded text to give him the next n lines via an ajax call.
What is the best way to detect this event?
You should compare the textarea.scrollHeight
to the textarea.scrollTop
- the closer they are, the closer you are to the end of your text area.
You could work with the caret position (checking where it is and comparing it to your length).
Or, you could work with the scrollbar position. (or a combination of both)
精彩评论