jQuery实现定位滚动条位置

前端技术 2023/09/02 JavaScript

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

关键代码如下所示:

<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实现定位滚动条位置,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对phpstudy网站的支持!

本文地址:https://www.stayed.cn/item/4133

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。