Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Autoscroll赢得';t停止滚动。js/jquery/ajax问题_Javascript_Jquery_Ajax_Livechat - Fatal编程技术网

Javascript Autoscroll赢得';t停止滚动。js/jquery/ajax问题

Javascript Autoscroll赢得';t停止滚动。js/jquery/ajax问题,javascript,jquery,ajax,livechat,Javascript,Jquery,Ajax,Livechat,我的聊天框不会停止自动滚动(它不会让我向上滚动),我知道问题出在哪里。。。然而,我不知道如何避开它。我需要聊天框自动滚动,但我希望能够在同一时间向上滚动 这是问题的症结所在 //Load the file containing the chat log function loadLog(){ $("#chatbox").animate({ scrollTop: 99999 }, 'normal'); $.ajax({ url: "log.html",

我的聊天框不会停止自动滚动(它不会让我向上滚动),我知道问题出在哪里。。。然而,我不知道如何避开它。我需要聊天框自动滚动,但我希望能够在同一时间向上滚动

这是问题的症结所在

//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');



        }               

    });
}

您可以检查scoll位置何时处于启用状态。如果显示为底部,则滚动至底部

//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');



        }               

    });
}

顺便说一句,您没有反复使用AJAX进行轮询,而是考虑过使用WebSocket吗?没有,我甚至不知道什么是WebSocket设置一个全局变量maxScroll,ajax成功后,仅当scrollTop>=99999时更新。这应该可以工作