美文网首页
jQuery实现滚动条滚动到子元素位置(方便定位)

jQuery实现滚动条滚动到子元素位置(方便定位)

作者: 遇而记起 | 来源:发表于2021-08-26 12:25 被阅读0次

关键代码如下所示:

<div class="of-y"id="nurse">

  <table class="high width"id="nurse-plan">

        <tr id="tr-one"></tr>

        <tr id="tr-two"></tr>

        <tr id="tr-three"></tr>

        <tr id="tr-four"></tr>

    </table>

</div>

jQuery:

$("#nurse").scrollTop($("#nurse").scrollTop() + $('#tr-three').offset().top - $("#nurse").offset().top); --普通

$("#nurse").animate({ scrollTop: $("#nurse").scrollTop() + $('#tr-three').offset().top - $("#nurse").offset().top }, 1000); --有动画效果

相关文章

网友评论

      本文标题:jQuery实现滚动条滚动到子元素位置(方便定位)

      本文链接:https://www.haomeiwen.com/subject/mbtuiltx.html