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

时间:2014-05-05    点击:72   
这里有一个方法可以将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 is()函数用法3例
使用原生js封装webapp滑动效果(惯性滑动、滑动回弹)
一些老手都不一定知道的JavaScript技巧
jQuery中的$.ajax()方法应用
jquery判断元素是否隐藏的多种方法
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved