爱程序网

如何通过JQuery将DIV的滚动条滚动到指定的位置

来源: 阅读:

这里有一个方法可以将DIV的滚动条滚动到其子元素所在的位置,方便自动定位。

var container = $('div'),
    inner = $('#inner');

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

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

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助