offsetTop 实现滚动条内内容定位

js代码:

var _parent_top = document.getElementsByClassName('parent')[0].offsetTop;
var _phase_top = document.getElementsByClassName('children')[0].offsetTop;
$('.task-exe-phase-container').animate({scrollTop:(_phase_top - _parent_top)+'px'},500);

注:找到父元素距离当前顶部的滚动距离,找到需要定位的元素距离顶部的距离。他们的差就是滚动条需要滚动的距离。


原文地址:https://www.cnblogs.com/zhucj/p/10065701.html