WhatsApp Web:滚动到顶部按钮
添加一个浮动按钮,一键将当前打开的对话历史滚动到顶部。
可复制的代码
// Add a floating button to scroll the open chat to the very top
(function () {
if (document.getElementById('jz-wa-scroll-top')) return;
const btn = document.createElement('button');
btn.id = 'jz-wa-scroll-top';
btn.textContent = '↑';
btn.style.cssText = 'position:fixed;right:20px;bottom:80px;z-index:9999;width:42px;height:42px;border-radius:50%;border:none;background:#25d366;color:#fff;font-size:20px;cursor:pointer;box-shadow:0 3px 10px rgba(0,0,0,0.25);';
btn.addEventListener('click', function () {
const pane = document.querySelector('#main [data-testid="conversation-panel-messages"], #main div[role="application"]');
if (pane) pane.scrollTop = 0;
});
document.body.appendChild(btn);
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。