首页 > 语言 > JavaScript > 正文

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

2024-05-06 16:05:10
字体:
来源:转载
供稿:网友
本文为大家介绍下将DIV的滚动条滚动到其子元素所在的位置,方便自动定位,需要的朋友可以参考下

这里有一个方法可以将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插件即可完成所需的效果,非常好用!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选