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时更新。这应该可以工作