JQueryでDIVのスクロールバーを指定した位置にスクロールする方法

790 ワード

ここでは、DIVのスクロールバーをサブエレメントの位置にスクロールし、自動位置決めを容易にする方法があります.
var container = $('div'),
    scrollTo = $('#row_8');

container.scrollTop(
    scrollTo.offset().top - container.offset().top + container.scrollTop()
);

// Or you can animate the scrolling:
container.animate({
    scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()
});​

JQueryプラグインを必要とせずに必要な効果を達成でき、とても使いやすいです!