简体   繁体   English

我怎样才能让它显示这个元素的底部? (HTML, CSS, JS)

[英]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.

相关问题 如何使用 HTML、CSS 或 JS 使元素默认处于活动状态? - How can I use HTML, CSS, or JS to make an element active by default? 如何使用 HTML、CSS 和 Js 使 div 位于所有屏幕类型中的特定元素旁边? - How can i make a div stay next to a specifc element in all Screens types with HTML, CSS and Js? 如何在 HTML/CSS 中制作计数器 - How can I make a counter in HTML/CSS 如何在底部创建一个html滚动条? - how can I make a html scrollbar start at the bottom? 如何在悬停时制作HTML框,并使用JS或CSS显示其下方的文本 - How can I make an HTML box slide on hover and reveal the text underneath it using JS or CSS Vue.js:如何使动态创建的 HTML 使用范围为 CSS? - Vue.js: How can I make dynamically created HTML use scoped CSS? 如何在没有插入符号的情况下使用 HTML、CSS 和 JS 在用户悬停时制作书写动画(文本更改) - How can I make a writing animation(change of text) on a users hover with HTML, CSS, and JS, just without the caret 如何使输入框中的第三个项目具有不同的颜色? (JS、HTML、CSS) - How can I make the third item entered into an input box a different color? (JS, HTML, CSS) 如何在CSS规则中显示有display:none的元素? - How can I show an element that has display: none in a CSS rule? 如何让菜单从底部按钮向上滑动而不是仅仅出现? HTML/CSS/JS - How do I get the menu to slide up from bottom button instead of just appearing? HTML/CSS/JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM