2017-12-09 2 views
0

실시간 메시지를 볼 수 없기 때문에 어떻게 채팅을 할 수 있습니까? 나는 이미 실제의 마지막 메시지채팅 상자의 자동 스크롤 JavaScript 기능

에 있어야 내가 첫 번째로드에서 내 스타일의 오버 플로우

<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> 

을 넣어 내 내 DIV ID를 호출 할 대화를 말하면 마지막 메시지가 나타납니다.

답변

1

이것은 당신이 찾고있는 것입니다. 희망, 도움이됩니다.

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>

+0

그것 때문에 내 스크램블 구문의 아마 작동하지 않았다 : '

' –

+0

chatMessage가있다 JS에서 실시간 기능에 연결되어 있기 때문에 내가 상단에 스크롤 ID를 만들려고 'function getMessages() { $ .get (' index.php/********/getMessage', function (data) { $ (". chatMessage") .html (데이터); }); } getMessages ( ), 500); –

+0

@HanthonyTagam 그런 다음 방금 자식 div 컨테이너에 대한 ID를 만들고 스크롤 한 이름을 방금 편집 한 javascript의 이름으로 바꿉니다. 그것이 도움이된다면 답을 표시하십시오, 환호하십시오. –

관련 문제