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

时间:2012-09-19 04:02:12

标签: javascript jquery ajax livechat

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

这是问题的a live example

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



        }               

    });
}

1 个答案:

答案 0 :(得分:1)

您可以检查滚动位置的时间。如果它作为底部然后滚动到底部

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



        }               

    });
}
相关问题