Skip to content

Commit 5a6969b

Browse files
committed
修复图片消息自动滚动的距离不够
1 parent 59a6556 commit 5a6969b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

www/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function addLinkItem(uid, file) {
222222
<div class="chat-item_content">${contentHtml}</div>
223223
`;
224224

225-
// 如果是图片,添加点击事件
225+
// 如果是图片,添加点击事件和加载完成后的滚动
226226
if (isImage) {
227227
const img = chatItem.querySelector('img');
228228
img.onclick = function() {
@@ -266,10 +266,19 @@ function addLinkItem(uid, file) {
266266
}
267267
};
268268
};
269+
270+
// 等待图片加载完成后再滚动
271+
img.onload = function() {
272+
chatBox.scrollTop = chatBox.scrollHeight;
273+
};
269274
}
270275

271276
chatBox.appendChild(chatItem);
272-
chatBox.scrollTop = chatBox.scrollHeight;
277+
278+
// 如果不是图片,立即滚动
279+
if (!isImage) {
280+
chatBox.scrollTop = chatBox.scrollHeight;
281+
}
273282
}
274283

275284
function addChatItem(uid, message) {

0 commit comments

Comments
 (0)