I'm making something where a textarea gets more and more text appended. In firefox, the textarea scroll back up to the top each time.
I currently have something like textarea.scrollTop=1000000;
to scroll it back down each time it changes, but it still goes up to the top for a very short time.
Is there any way to stop it doing so?
views:
121answers:
2
A:
i thing that is problem of adding the content via the script, paste your code which append text to your textarea
Dobiatowski
2010-07-08 10:52:18
the code I use to add to textarea is `textarea.value+=string`
tmim
2010-07-08 13:36:36
try to use `textarea.value = textarea.value + string;` , i know that some time ago i had the same problem and i changed the method of adding new content. and it work out but im not sure that this is it.
Dobiatowski
2010-07-08 21:39:38
A:
I ran into this problem, too. It happens in IE and Firefox but not Opera and Chrome.
I thought of hiding the momentary jumps to the top by "double-buffering" changes to the textarea:
- Create two textareas with the exact same properties and dimensions. Only one of these is visible; the other one is hidden.
- Append text to the hidden textarea: set [the value of the hidden textarea] to [the value of the visible textarea] + [text to append]. (The textarea will automatically scroll to the top, but this textarea is hidden!)
- Scroll the hidden textarea to the bottom: set scrollTop to a high integer value like (-1 >>> 1).
- Swap the hidden textarea with the visible one. Now the new text is shown, sans jumping to top!
You can swap the hidden/visible textareas by using one of two methods:
- Use absolute positioning to place the textareas on top of each other in conjunction with toggling their visible property.
- Swap the actual DOM elements. I'm not sure if this will introduce a new type of "flicker." You may have to create a div to contain the visible textarea so the layout of the page doesn't keep changing...
Leftium
2010-07-21 18:46:34