私は mCustomScrollbar を使用しており、スクロールの上下にコンテンツを動的にロードしようとしています (もちろん、同時にではありません)。
http://manos.malihu.gr/jquery-custom-content-scroller/
コンテンツを追加すると、スクロールは正しい位置に留まります (スクロールした位置に留まり、スクロールバーの位置が自動的に変更されるため、下にスクロールして新しいコンテンツを表示できます)。
ただし、コンテンツを先頭に追加 (スクロールバーの一番上に配置) し、ユーザーが上にスクロールすると、コンテンツは読み込まれますが、スクロールバーは強制的に上に移動します。一番下にコンテンツを追加するときとまったく同じように動作させたい: ユーザーが上にスクロールして新しいコンテンツを表示できるようにする。
$(selector).mCustomScrollbar({
mouseWheel: {
scrollAmount: 500,
preventDefault: true
},
callbacks: {
advanced: {
updateOnContentResize: true
},
onScroll: function() {
// this.mcs.topPct contains the current scroll position (when scroll animation is completed.
// it can be between 0-100, where 100 is bottom and 0 is top
//
// my scroll starts on the bottom, and when this.mcs.topPct is 0
// I load dynamic content and place it on the very top of all content
// this causes the scroll to display this content immediately,
// and I would like the user to manually scroll up to see the added content.
}
}
});