gpt4 book ai didi

Javascript 聊天文本到底部

转载 作者:行者123 更新时间:2023-11-28 05:05:11 26 4
gpt4 key购买 nike

我用 javascript 创建了一个聊天系统。发送的消息在右边,接收的在左边。
现在我想将它们显示在底部(目前它们在顶部)。但是如果我将父 div 设置在底部,那么发送和接收的消息都会显示在一侧。

css: 截图因为这个页面无法格式化我的 css wow.. https://s15.postimg.org/kav7m3x3v/css_SO.png

win.document.getElementById('input-text-chat').onkeyup = function (e) {
if (e.keyCode != 13) return;
// removing trailing/leading whitespace
this.value = this.value.replace(/^\s+|\s+$/g, '');

var a = new Date();
var b = a.getHours();
var c = a.getMinutes();
var d = a.getSeconds();
if (b < 10) {
b = '0' + b;
}
if (c < 10) {
c = '0' + c;
}
if (d < 10) {
d = '0' + d;
}
var time = b + ':' + c + ':' + d;

if (!this.value.length) return
connection.send('<div class="chat-OutputGET bubbleGET"> <font color="white"> User(' + time + '): ' + this.value + '</font></div>');
console.log(connection.send);
console.log('User (' + time + '): ' + this.value);
appendDIV('<div class="chat-OutputSEND bubble"> <font color="white"> Me (' + time + '): ' + this.value + '</font></div>');
this.value = '';
};
var chatContainer = win.document.querySelector('.chat-output');

function appendDIV(event) {
console.log(event);
var div = document.createElement('div');
div.innerHTML = event.data || event;

chatContainer.appendChild(div);
div.tabIndex = 0;
div.focus();
win.document.getElementById('input-text-chat').focus();
}
connection.onmessage = appendDIV;

}
<div id="chatHtml" style="display: none;">
<link rel="stylesheet" href="style/main.css">
<div id=chatOutput class="chat-output"></div>
<textarea class="form-control" rows="1" id="input-text-chat" placeholder="Enter Text Chat"></textarea>
<div id="chat-container">
</div>
</div>

最佳答案

完成,我将“聊天输出”的位置更改为绝对值,重点是将左右设置为 0。

关于Javascript 聊天文本到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39866173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com