当前位置: 首页 > news >正文

纯CSS实现自动滚动到底部

 

<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>自动滚动到底部</title><style>* {box-sizing: border-box;}body {margin: 0;height: 100vh;display: flex;flex-direction: column;}.chater {flex: 1;overflow: auto;padding: 1em;display: flex;flex-direction: column-reverse;}.msger {flex: 1;display: flex;flex-direction: column;}.msger > pre {background-color: #eee;padding: 1em;border-radius: 8px;white-space: pre-wrap;}.msger .user {align-self: flex-end;margin-left: 10vw;}.msger .ai {align-self: flex-start;margin-right: 10vw;}.sender {flex-shrink: 0;padding: 1em;}</style></head><body><div class="chater"><div class="msger"></div></div><div class="sender"><input type="text" /><button onclick="send()">发送</button></div><script>function send() {document.querySelector('.chater').scrollTop = document.querySelector('.chater').scrollHeightconst pre = document.createElement('pre')pre.className = 'user'pre.textContent = document.querySelector('input').valuedocument.querySelector('.msger').appendChild(pre)const pre2 = document.createElement('pre')pre2.className = 'ai'const timer = setInterval(() => {pre2.textContent +=String.fromCharCode(Math.floor(Math.random() * 122) + 65).repeat(Math.ceil(Math.random() * 10)) + (Math.random() < 0.2 ? '\n' : ' ')if (pre2.textContent.length > 1000) clearInterval(timer)}, 50)document.querySelector('.msger').appendChild(pre2)}</script></body>
</html>

相关文章:

  • C++ 二叉搜索树
  • 安装多个DevEco Studio版本,如何才能保证各个版本不冲突?
  • 「仓颉编程语言」Demo
  • 网络互连与互联网3
  • 从零到精通:用 GoFrame 和 go-resty 优雅调用第三方 HTTP API
  • 消息队列生产者投递的高可靠性与一致性保障方案
  • 【Linux】深入理解Linux文件系统:从C接口到内核设计哲学
  • MCP 协议:技术架构与核心机制深度解析——为智能时代打造统一“接口”
  • Linux | I.MX6ULL Uboot 编译(12)
  • opencv函数展示3
  • IntelliSense 已完成初始化,但在尝试加载文档时出错
  • 解读固定资产管理系统的核心功能模块
  • 中建海龙:模块化集成建筑重构人类居住文明的未来范式
  • PoCL环境搭建
  • 时间序列预测——概述
  • 大模型微服务架构模块实现方案,基于LLaMA Factory和Nebius Cloud实现模型精调的标准流程及代码
  • #去除知乎中“盐选”付费故事
  • 6.8.最小生成树
  • Java研学-MybatisPlus(一)
  • 6.VTK 颜色
  • 美方因涉港问题对中国官员滥施非法单边制裁,外交部:强烈谴责,对等反制
  • 上海农房翻建为何难?基层盼政策适度松动
  • 中宣部等十部门联合印发《新时代职业道德建设实施纲要》
  • 美国防部查信息外泄,防长四名亲信被解职
  • 林间徐行寻风眠——关于浙美“徐宗帅捐赠纪念展”
  • 网信部门持续整治利用未成年人形象不当牟利问题