[英]autoscroll javascript function in chatbox
我如何实现聊天框上的向下滚动,因为我看不到实时消息。 我希望在我的div ID上调用它,我将样式溢出
<script>
//scroll to bottom
window.onload=toBottom;
function toBottom(){
window.scrollTo(0, document.body.scrollHeight);
}//end of scroll to bottom
</script>
查看零件
<div class="scrollMessage w3-padding div" onload="toBottom" id="scroll" style="overflow-y:scroll;height: 460px;">
<?php include 'getMessage.php'; ?>
</div>
第一次加载时,它应该已经在最后一条消息上
在实际的聊天对话中,它也会显示在最后一条消息上
这就是您要寻找的。 希望能帮助到你。
var objDiv = document.getElementById("scroll2"); //Obtain the ID of the chat div window.onload = toBottom; function toBottom() { objDiv.scrollTop = objDiv.scrollHeight; //Set the scroll offset position to the height of the chat div }
<div id="scroll"> <div class="scrollMessage w3-padding div" onload="toBottom" id="scroll2" style="overflow-y:scroll;height: 200px;width:150px;"> <!--<?php include 'getMessage.php'; ?>--> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> Random messages <br> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.