【发布时间】:2010-12-03 19:10:57
【问题描述】:
jScrollPane 是一个很棒的 jQuery 插件,它可以修改默认浏览器滚动条。我正在开发一个将使用 jScrollPane 的聊天应用程序。到目前为止它工作得很好,除了我无法确定最大滚动高度。这是我想要做的:
$(function ()
{
$('#chatPane').jScrollPane();
var api = $('#chatPane').data('jsp');
setInterval(function ()
{
$.ajax(
{
url: "Home/GetMessage",
type: "POST",
success: function (response)
{
// This next line is where the issue occurs. I need to check if the current scroll position is equal to the max scroll position. This is to implement the auto scroll if the user has scrolled to the bottom of the chat.
var atBottom = (api.getContentPane().getContentPositionY() == api.getContentPane().getMaxScrollHeight()??????);
api.getContentPane().append(response);
api.reinitialise();
if (atBottom)
api.scrollToBottom();
},
error: function (xhr, textStatus, errorThrown)
{
alert(textStatus);
}
});
}, 1000);
});
getMaxScrollHeight 不存在。我需要一些方法来确定最大滚动高度。
编辑:我让它与对 ajax 成功函数的以下更改一起工作。但是,如果有人知道比滚动到底部、获取当前位置、然后滚动回上一个位置更好的方法,那将不胜感激。
success: function (response)
{
var currentPosition = api.getContentPositionY();
api.scrollToBottom();
var maxPosition = api.getContentPositionY();
api.scrollToY(currentPosition);
var atBottom = (currentPosition == maxPosition);
api.getContentPane().append(response);
api.reinitialise();
if (atBottom)
api.scrollToBottom();
}
【问题讨论】:
标签: javascript jquery ajax jquery-plugins jscrollpane