Scroll to a text position in Javascript

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-04-02T15:15:24Z Indexed on 2010/04/02 15:23 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I have a real-time HTML editor, with a textarea on the left for code entry, and a 'preview' DIV on the right to contain the preview of the code entered. At the moment, when editing the code in the left pane, the preview just sits where it is, so often the part of the code you're editing is not in the visible area of the preview (especially when images are involved).

My question is how do I make the preview scroll to show the part of the code that's currently being edited?

Here is the page I have so far: http://www.caerphoto.com/rtedit.html You'll notice in the source I have a (currently unused) matchPreview() function that tries to match the scroll position of the preview based on the scroll position of the textarea, but obviously if images or large text are involved the two panes no longer match.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html