更新时如何让文本区域保持滚动到底部 [英] How to have a textarea to keep scrolled to the bottom when updated

查看:24
本文介绍了更新时如何让文本区域保持滚动到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题有点离题,所以我会尽力解释这个问题.

My problem is a bit off the cuff here, so I'll try to explain this best I can.

我有一个文本区域,具有 #object{overflow:hidden;resize:none;} 的 css.我试图防止它产生滚动条,同时也调整自己的大小.此文本区域与外部脚本的控制台同步,这意味着它会更新.但是,默认情况下,除非您突出显示文本,否则它将保持在顶部,拖到元素的底部.这自然是除使用箭头键外向下滚动的唯一方法.

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.

推荐答案

您可以通过 javascript 来完成.使用 scrollHeight 属性设置文本区域的 scrollTop 属性,如下所示:

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 

这篇关于更新时如何让文本区域保持滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆