自动滚动不会停止滚动 .js/jquery/ajax 问题



我的聊天框不会停止自动滚动(它不会让我向上滚动),我知道问题出在哪里......但是我不知道如何绕过它。我需要聊天框自动滚动,但我希望能够同时向上滚动。

这是该问题的一个活生生的例子。

//Load the file containing the chat log
function loadLog(){     
    $("#chatbox").animate({ scrollTop: 99999 }, 'normal');
    $.ajax({
        url: "log.html",
        cache: false,
        success: function(html){        $("#chatbox").animate({ scrollTop: 99999 }, 'normal');
        $("#chatbox").html(html);
        $("#chatbox").animate({ scrollTop: 99999 }, 'normal');

        }               
    });
}

您可以检查斯科尔位置何时。 如果它作为底部,则滚动到底部

//Load the file containing the chat log
function loadLog(){     
  // remove  $("#chatbox").animate({ scrollTop: 99999 }, 'normal');
    $.ajax({
        url: "log.html",
        cache: false,
        success: function(html){     
        var chatbox= $("#chatbox");
        var atBottom = (chatbox[0].scrollHeight - chatbox.scrollTop() == chatbox.outerHeight());
        chatbox.html(html);
        if (atBottom )
         chatbox.animate({ scrollTop: 99999 }, 'normal');

        }               
    });
}

最新更新