通过JQuery将DIV的滚动条滚动到指定的位置方便自动定位

2019-12-21,,,,

这里有一个方法可以将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插件即可完成所需的效果,非常好用!

您可能感兴趣的文章:

  • jQuery简单获取DIV和A标签元素位置的方法
  • jQuery实现将div中滚动条滚动到指定位置的方法
  • jQuery判断div随滚动条滚动到一定位置后停止
  • JQuery实现点击div以外的位置隐藏该div窗口
  • 使用jQuery实现两个div中按钮互换位置的实例代码

《通过JQuery将DIV的滚动条滚动到指定的位置方便自动定位.doc》

下载本文的Word格式文档,以方便收藏与打印。