[英]How can i make it show the bottom of this element? (HTML, CSS, JS)
I want users to be able to see message that are sent after, which they cant see cause it runs out of room and i dont want the element to constantly expand so it wont ruin/destroy over elements.我希望用户能够看到之后发送的消息,他们看不到因为空间不足,我不希望元素不断扩展,这样它就不会破坏/破坏元素。
How can i make this show the what is being sent after AA?我怎样才能让这个显示在 AA 之后发送的内容? https://i.imgur.com/g13UDBg.png https://i.imgur.com/g13UDBg.png
using Socket.io, jquery, js, html and css.使用 Socket.io、jquery、js、html 和 ZC7A628CBA22E28EB16AZ5F5C6AE22。
<!-- code -->
<div style="float:right;margin-right:3%; height:550px;">
<ul id="messages" style="height: 85%;"></ul>
<form action="" style="">
<input id="m" autocomplete="off" /> <button class="btn-primary">Send</button>
</form>
</center>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(function () {
var socket = io();
$('form').submit(function(e){
e.preventDefault(); // prevents page reloading
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
});
</script>
For all the data to be visible vertically you must add要使所有数据垂直可见,您必须添加
CSS CSS
overflow-y : scroll;
to your ul
.给你的ul
。
After that for the smooth motion for the scroll down after the data inserted add the animation as之后,在插入数据后向下滚动的平滑运动添加 animation 为
Jquery Jquery
$(document).ready(function(){
$("input").keyup(function(){
$('ul').animate({scrollTop: '100%'}, 800);
});
});
One solution is to add a scrollbar to your chat box,一种解决方案是在您的聊天框中添加滚动条,
<!-- code -->
<div style="float:right;margin-right:3%; height:550px; ">
<ul id="messages" style="height: 85%;overflow-y: scroll;"></ul>
<form action="" style="">
<input id="m" autocomplete="off" /> <button class="btn-primary">Send</button>
</form>
</center>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(function () {
var socket = io();
$('form').submit(function(e){
e.preventDefault(); // prevents page reloading
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
});
</script>
This will give you something that looks like this:这将为您提供如下所示的内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.