If you don't know when data will be added to #data
, you could set an interval to update the element's scrollTop to its scrollHeight every couple of seconds.
(如果您不知道何时将数据添加到#data
,您可以设置一个间隔,以便每隔几秒钟将元素的scrollTop更新为其scrollHeight。)
If you are controlling when data is added, just call the internal of the following function after the data has been added.(如果您正在控制何时添加数据,则只需在添加数据后调用以下函数的内部。)
window.setInterval(function() {
var elem = document.getElementById('data');
elem.scrollTop = elem.scrollHeight;
}, 5000);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…