如何使div中的ul标签可滚动

时间:2018-11-06 10:36:42

标签: javascript jquery html ajax

我是设计新手,所以我正在制作一个聊天框,但是当在框中填充值后,它的div上升了,如何使该div向下滚动,我尝试了来自互联网的所有解决方案,但是没有一个起作用,所以我有两个问题div滚动应该在底部,并且div刷新2秒 这是代码

<div class="col-sm-3 col-sm-offset-4 frame" style='margin-top:-8px;' id='huge'>
<ul id="mylist" stye="">

<?php 
  $conn = new PDO("mysql:host=localhost;dbname=chatbox",'root');
  $stmt = $conn->prepare("select * from chatbox order by created");
  $stmt->execute();
  if($stmt->rowCount() > 0)
  {
    while($row = $stmt->fetch(PDO::FETCH_ASSOC))
    {
        if($_SESSION['username']==$row['user_name']){
?>
<li style="width:100%" id="bottom">
  <div class="msj macro">
    <div class="avatar"><img class="img-circle" style="width:100%;" src="img/unknown.png" /></div>
    <div class="text text-l" id="">
      <p>
        <?php echo $row['msg']; ?>
      </p>
      <p><small><?php echo date('H:i', strtotime($row['created']));?></small></p>
    </div>
  </div>
</li>
<?php }else{ ?>
<li style="width:100%; color:white;" id="myid">

  <div class="msj-rta macro">
    <div class="text text-r">
      <p>
        <?php echo $row['msg']; ?>
      </p>
      <p><small><?php echo date('H:i', strtotime($row['created']));?></small></p>
    </div>
    <div class="avatar" style="padding:0px 0px 0px 10px !important">
      <img class="img-circle" style="width:100%;" src="img/unknown.png" /></div>
</li>
<?php 
    }}}
?>
</ul>
<div>
<form role='insert'>
  <input type='hidden' class="mytext" name='user_name' id='user_name' value="<?php echo $_SESSION['username'] ?>" />
  <div class="msj-rta macro" style='margin-right:30px;margin-bottom:-40px;'>
    <div class="text text-r" style="background:whitesmoke !important;">
      <input class="mytext" placeholder="Type a message" name='msg' id='msg' />
    </div>
  </div>
  <div style="padding-left:240px;margin-bottom:20px;">
    <button type="submit" class="login-button" id='submit'><i class="fa fa-chevron-right"></i></button>
  </div>
</form>
</div>
</div>
</body>
 <script>
 $(document).ready(function() {
  $("#submit").click(function() {
    var user_name = $("#user_name").val();
    var msg = $("#msg").val();
    if (msg == '' || msg == '') {
      alert("Please Fill All Fields");
    } else {
      $.ajax({
        type: "POST",
        url: "user/chatInsert.php",
        data: 'user_name=' + user_name + '&msg=' + msg,
        cache: false,
        success: function(result) {
          window.location.reload();
        }
      });
    }
    return false;
  });
});

我尝试了所有可能的代码来实现我的代码,但是没有任何效果,所以请尝试帮助我。

1 个答案:

答案 0 :(得分:0)

我不确定您要问的是什么,但是根据您的标题,这就是使块可滚动的方式。

.scrollable {
  overflow: auto;
  height: 100px;
}
<div class="scrollable">
  <ul>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
    <li>this is a list</li>
  </ul>
</div>