问题描述
我有一个文本区域,有css
code> #object {overflow:hidden; resize:none;} 。我试图阻止它产生滚动条,同时也调整自身。此textarea与外部脚本的控制台同步,意味着它更新。默认情况下,它将保持在顶部,除非你突出显示文本,拖动到元素的底部。这将是唯一的方法向下滚动,而不是用箭头键,自然。以编程方式,有没有办法在更新时将文本区域保持在底部?
你可以通过javascript来实现。使用 scrollHeight
属性设置文本区域的 scrollTop
属性,如下所示:
document.getElementById(textarea)。scrollTop = document.getElementById(textarea)。scrollHeight
My problem is a bit off the cuff here, so I'll try to explain this best I can.
I have a text area, having css of #object{overflow:hidden;resize:none;}
. I am trying to prevent it from spawning scroll bar while also resizing itself. This textarea is synced with an external script's console meaning it updates. By default however, it will stay at the top unless you highlight text, dragging off to the bottom of the element. This would be the only way to scroll down other than with arrow keys, naturally.
Programmatically, is there any way to keep the text area down to the bottom upon updating? It would be nice to have it auto-scroll to accommodate its use case.
You can do it by javascript. Set the scrollTop
property of text area with scrollHeight
property like below:
document.getElementById("textarea").scrollTop = document.getElementById("textarea").scrollHeight
这篇关于如何让textarea更新时保持滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!