Closed Bug 123075 Opened 24 years ago Closed 22 years ago

Allow scrolling of textarea with JavaScript

Categories

(Core :: DOM: Core & HTML, enhancement, P4)

All
Other
enhancement

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: jwatt, Unassigned)

Details

IE allows textareas to be scrolled by using: textareaObj.scrollTop = <length>; where <length> is the distance to scroll down. If the length exceeds the distance then the textarea is simply scrolled to the end. This can alternatively be done using: textareaObj.scrollTop = textareaObj.scrollHeight; // scroll to end There is also scrollLeft and scrollWidth to allow this to be done in horizontally. Several of my scripts (including a multiline calculator and a CAD script) repeatedly add textual results to the end of a textarea and naturally need to scroll to the end to show the last result (while allowing the user to scroll up manualy if they want to see previous results). I am sure that there are other applications and other people who would find the means to scroll a textarea useful. Perhaps the scrollTo() and scrollBy() methods could be added to textareas as a means to allow this in Mozilla. Other things to consider would be if the page is ltr or rtl, and providing a means of determining the possible amount of scroll (both horizontally and vertically).
To DOM.
Assignee: rods → jst
Component: HTML Form Controls → DOM Mozilla Extensions
QA Contact: madhur → lchiang
Priority: -- → P4
QA Contact: lchiang → ian
Mass-reassigning bugs to dom_bugs@netscape.com
Assignee: jst → dom_bugs
Please, make this "bug" alive. I'm making shorcuts for fast text formatting in my WikiEdit - http://wiki.oversite.ru/WikiEdit (based on simple textarea with autoindent (made through the JavaScript)). But nasty behaviour of Mozilla browser that scrolls up on every change in textarea content made by script, makes my work absolutely seemless. Please!
The scrolltop,scrollleft, scrollheight and scrollwidth properties are working at least in the latest versions of Mozilla (Moz 1.4b). See: http://home.hccnet.nl/m.wargers/test/mozilla/scrolltobottom.htm I would say this bug has been fixed somehow. Determining the amount of scroll, you could do with some scripting yourself. You could experiment with textarea offsetheight property rows property scrollheight and the amount of returns in the textarea value property. The amount of soft returns (the returns added by Mozilla in order to wrap text in textareas) you would need also, but I can't think of a way to get these.
Thanks for fixed scrollTop and friends. But there's one more question. Let's imagine that we have some (selected) text. But we have no ideas where is it located in textarea. It can be out of the visible part. MSIE has this method for scrolling to this text: tr = document.selection.createRange(); tr.scrollIntoView(false); //for end of selection aligned to end of scrolled area or tr.scrollIntoView(true); //for beginning of selection aligned to top of scrolled area Are there any methods to do this task in Mozilla? Are there any plans to implement it if not?
There is no scrollIntoView method for the range object. For HTML elements there is a scrollIntoView method. I've sort of made a simple and not complete (no scrolling to the right, no arguments, extra scrolling inside element only for textareas') scrollIntoView method for the range object. http://home.hccnet.nl/m.wargers/test/mozilla/scrollintoviewrange.htm I already said it is not complete, and although I could it make more complete, it would be extremly difficult (or a lot of work, which is the same) to let it behave correctly. In textarea's I can count the hard returns, so I can see where the scrollposition of the selection is. But I can't count the 'soft' returns (the returns when Mozilla wraps the text), so with a lot of soft returns, it doesn't work anymore. In other elements I get other problems, but basically I could solve it, except again the 'soft' returns problem. So I think this method is quite necessary. That's why I've file a bug for this one: Bug 220262 http://bugzilla.mozilla.org/show_bug.cgi?id=220262 This bug can still be closed by the way.
Thanks for the comments, Martijn. According to last comment, marking WORKSFORME because scrolling of a textarea with JavaScript seems to work now (please reopen if you disagree, if so, please attach a testcase, thanks!)
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → WORKSFORME
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.