mipengine / mip2

MIP (移动网页加速器)通过优化网页JS、控制资源加载顺序,达到加速网页的效果。
https://www.mipengine.org/
MIT License
184 stars 49 forks source link

MIP.viewer.page.scrollToHash 在锚点节点存在 position: relative 祖先元素时会导致锚点不准确 #673

Closed clark-t closed 5 years ago

clark-t commented 5 years ago

BUG 描述 MIP.viewer.page.scrollToHash 在锚点节点存在 position: relative 祖先元素时会导致锚点不准确,错误原因基本定位是 MIP.viewer.page.scrollToHash 方法中获取锚点节点的 offsetTop 方式不对,应该沿着 offsetParent 逐渐将 offsetTop 累积起来获得。

复现步骤

  1. 准备简单的 MIP HTML 页面包含如下片段,其中 bias 节点需要存在一定高度是的 position-relative 本身存在偏移
    <div class="bias"></div>
    <div class="position-relative">
    <div id="target"></div>
    </div>
  2. 在控制台输入 MIP.viewer.page.scrollToHash('#target')
  3. 发现滚的不对

期望结果 可以仿造 Jquery offset().top 的计算方法实现

截图 如果合适,添加问题相关的截图

环境及版本信息:

其他信息 其他补充信息

clark-t commented 5 years ago

done