jScrollPaneは、デフォルトのブラウザスクロールバーを変更する素晴らしいjQueryプラグインです。 jScrollPaneを使用するチャットアプリケーションを開発しています。私は最大のスクロールの高さを決定することができないという事実を除いてこれまでのところ素晴らしいです。私がやろうとしていることは次のとおりです。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は存在しません。最大スクロールの高さを決定する方法が必要です。
EDIT:私は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();
}
興味深い考えです。スクロール・ボトム()をシミュレートする方法はありますか? – Chev
私は2つの方法が考えられます:最初に、ページ上の実際のオブジェクトと同じプロパティを持つメモリ内のJavascriptコピーを作成し、その上でコマンドを実行します。 2番目の方法は、現在のスクロール位置を保存し、ライブオブジェクトに対してコマンドを実行して、前のスクロール位置を復元することです。これは、UIがジャンプする可能性がありますので、使用可能かどうか確認するためにテストする必要があります。 – ChessWhiz
もう1つはできるが、UIジャンプが起こる可能性が高いことに同意する。メモリ内オブジェクトを作成するためのコードサンプルを使用して答えを更新できますか? – Chev