jQuery实现定位滚动条位置

 更新时间:2016年08月05日 11:18:27   作者:Mr.Bruce  
基于jQuery实现滚动条滚动到子元素位置以此来定位滚动条位置,下面是小编给大家带来的实现代码,代码比较简单,需要的朋友可以参考下

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

相关文章

最新评论