javascript - 我无法将我的 div 内容完美地滚动到底部
问题描述
我打算让我的自动滚动 div 内容滚动到底部,但不知何故它在最后一行之前至少滚动了 1 行。这个 div 应该像 textarea,但我不想使用 textarea,因为它不会格式化任何 html。
我试图让我的滚动条件减一,滚动事件加一
我有这样的javascript
var chatLog = document.getElementById('chatlog');
var logLength = chatLog.scrollHeight - chatLog.offsetHeight;
chatLog.innerHTML += msg;
if (chatLog.scrollTop < logLength - 1) {
chatLog.scrollTop = logLength + 1;
}
和这样的CSS
.chatlog {
width: 70%;
height: 200px;
word-wrap: break-word;
flex-direction: column-reverse;
background-color: #FFFFFF;
padding: 10px;
flex: 1;
overflow: auto;
font-size: 14px;
margin: 20px auto;
border-radius: 6px;
border: 0;
}
我希望输出将是最后一行,但实际输出是最后一行之前的一行。
解决方案
推荐阅读
- python - 如何将列表项的各个部分分成一个新列表?
- flutter - 尝试运行颤振项目失败
- macos - VirtualBox 无法在 Mac OS HighSierra 上打开
- c# - C# 以 3D 维度的速度将对象移动到另一个对象
- javascript - componentDidMount 未按预期执行
- file-upload - 使用多个线程进行文件上传有什么好处吗?
- node.js - 打印消息的公会名称
- javascript - 检查节点是否包含任何具有类的元素
- windows - 使用 PowerShell 远程安装 Windows 更新。(一些 PowerCLI)
- oop - 清洁架构:为什么不使用实体作为用例的请求模型(交互器)