确保该元素满足以下几个条件:
- 确保在获取该元素时,元素一定有高度height;
2.确保该元素的overflow为auto或者scroll;
以上两步缺一不可
function scrollLocation(father, scrollTo) {
// father.scrollTop(
// scrollTo.offset().top - father.offset().top + father.scrollTop()
// );
// Or you can animate the scrolling:
father.animate({
scrollTop: scrollTo.offset().top - father.offset().top + father.scrollTop()
}, 1000);
};
var father= $('div'),
scrollTo= $('#row_8');
scrollLocation(father, scrollTo)