これは、 http://www.balupton.com/sandbox/jquery-scrollto/demo/で使用されているコードの変更された抜粋です
。
あなたがやりたいことをするために:
// Fetch the scrollable div
$container = $('#scrollable');
// Fetch the target div
$target = $('#target');
// Prepare the Inline Element of the Container
var $inline = $('<span/>').css({
'position': 'absolute',
'top': '0px',
'left': '0px'
});
var position = $container.css('position');
// Insert the Inline Element of the Container
$container.css('position','relative');
$inline.appendTo($container);
// Determine the Offsets
var startOffset = $inline.offset().top,
targetOffset = $target.offset().top,
offsetDifference = targetOffset - startOffset;
// Perform the jump
$container.css('scrollTop',offsetDifference+'px')
ここにインラインを追加して、スクロール可能な領域内で正しい開始位置を取得できるようにします。オフセット差を使用するため、アニメーションを実行する場合は、別の場所にジャンプするのではなく、開始位置からアニメーションを作成します。