繁体   English   中英

自动向下滚动在拖动时不会向上滚动

[英]Auto scroll down is not scrolling up on dragging

我正在研究聊天应用程序的自动滚动,这就像每次我与某人进行对话时,对话页面都会自动向下滚动,当我发送消息时,滚动条会自动再次向下滚动每条收发消息。 使用此脚本,我实现了我的目标

$(document).ready(function() {
  setInterval(function() {
    $('#messagepost').load('conveyrefresh.php?value=<?php echo $mid."&picture=".$profilepic; ?>').scrollTop($("#messagepost").prop('scrollHeight'))
  }, 1000);
});

但是问题是,当我向上滚动时,它没有正常向上滚动,这意味着它没有固定在其上方,它会自动下降。

当我在每条发送消息和刷新页面的自动滚动旁边向上或向下滚动时,我希望它能正常工作。
搜索其解决方案后,我已经实现了此脚本(代替上面的脚本)-

var scrollpos = $("#messagepost").scrollTop();
var scrollpos = parseInt(scrollpos) + 520;
var scrollHeight = $("#messagepost").prop('scrollHeight');
if(scrollpos < scrollHeight)
    {
        $(document).ready(function() {
            setInterval(function () {
                $('#messagepost').load('conveyrefresh.php?value=<?php echo $mid."&picture=".$profilepic; ?>')
            }, 1000);
        });
    }
    else
    {
        $(document).ready(function() {
            setInterval(function () {
                $('#messagepost').load('conveyrefresh.php?value=<?php echo $mid."&picture=".$profilepic; ?>').scrollTop($("#messagepost").prop('scrollHeight'))


        }, 1000);});
    } 

但是在应用它之后,自动滚动功能就消失了。

花了很多时间后,我得到了一个解决方案,它正在为我工​​作。

<script type="text/javascript">
$("#messagepost").scrollTop($("#messagepost").prop('scrollHeight'));
    $(document).ready(function()
    {
        function updateChat(){
            $('#messagepost').load('conveyrefresh.php?value=<?php echo $mid."&picture=".$profilepic; ?>');
        }
    var chat = $("#messagepost").html();
setInterval(function () {
    updateChat();
    if(chat !== $("#messagepost").html()){

        $("#messagepost").scrollTop($("#messagepost").prop("scrollHeight"));
        chat = $("#messagepost").html();
    }
}, 1000);});



</script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM