开发者

"Type-writer Scrolling" in a web-page (JavaScript, CSS, and/or HTML)

开发者 https://www.devze.com 2023-02-14 07:52 出处:网络
I\'m trying to work out how to do \"type-writer scrolling\" in JavaScript for a textarea in a web-page, but I\'m having no luck. Essentially, what I\'m trying to do is make a textarea that, when a new

I'm trying to work out how to do "type-writer scrolling" in JavaScript for a textarea in a web-page, but I'm having no luck. Essentially, what I'm trying to do is make a textarea that, when a new line is created, scrolls the document automatically so as to keep the new line in the same position as the previous line. I've seen some开发者_C百科thing similar in desktop applications such as Write Monkey, but can't work out how to do it in JavaScript.

Thanks in advance for any suggestions!


Have a look at this page http://www.mediacollege.com/internet/javascript/page/scroll.html it shows basic scrolling methods

You could either scroll down by the height of your line (line-height css property) or scrollTo a specific point on the page


I have achieved something close to this, automatically expanding a textarea the way it is done on Facebook, but that was based on a conservative estimate, considering font size, box width, etc, to determine how many lines have probably wrapped. What you are describing is more exact -- down to the character.

The challenge here lies in knowing exactly how many lines are currently in the textarea and I can think of no way to do this. When you say, "a new line is created," you're talking about automatic wrapping and there is no way to read that or to trigger from it. It is part of the browser's hard-coded interpretation of many things, including your CSS.

If you went through with the whole typewriter theme, you would have a bell and the user would hit RETURN when they needed to, then you'd have your cue to scroll, but that sounds like a sure way to remind people why we no longer use typewriters.

0

精彩评论

暂无评论...
验证码 换一张
取 消