<script type="text/javascript">
var elementshoku = document.getElementById("1on1shoku");
var lastHeightshoku = elementshoku.scrollHeight;
function detectChangeshoku(){
var currentHeightshoku = elementshoku.scrollHeight;
if(lastHeightshoku != currentHeightshoku){
alert("xxx");
elementshoku.scrollTop = currentHeightshoku;
lastHeightshoku = currentHeightshoku;
}
}
var mesazhet_shoku = setInterval(detectChangeshoku, 200);
</script>
我正在聊天,我想在用户写消息时将 div 滚动到底部。我正在使用该功能,但它不起作用。我确实放了这个alert();
函数来检查上面的函数是否有效。我尝试了很多方法,但没有一个有效。知道为什么它不起作用吗?
谢谢
编辑:
我看到我的问题不够清楚。我正在聊天,如果有新消息,我希望 div 自动滚动到底部。在这个答案中,据说是这样做的https://stackoverflow.com/a/7666680/1932887但它对我不起作用。任何想法?