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

2021-08-26  本文已影响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); --有动画效果

上一篇 下一篇

猜你喜欢

热点阅读