学无先后,达者为师

网站首页 编程语言 正文

JQ实现将div的滚动条滚动到指定子元素所在的位置

作者:傻的太坏 更新时间: 2024-03-04 编程语言

确保该元素满足以下几个条件:

  1. 确保在获取该元素时,元素一定有高度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)

原文链接:https://blog.csdn.net/weixin_38897313/article/details/125780319

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新