DrLty

如何在 scrollBy 的时候保持滚动惯性?

  •  
  •   DrLty · Jul 5, 2022 · 1797 views
    This topic created in 1435 days ago, the information mentioned may be changed or developed.

    自己造的虚拟滚动 VerticalScrollViewer.js ,未渲染时有一个默认高度,渲染后高度固定。

    想实现从中间某个位置向上滚动时新 dom 渲染后当前页面显示内容位置不变。

    现在的做法是,拿到渲染好的组件高度后通过计算高度改变差值再通过 scrollBy 滚动过去。

    虽然能保持当前页面内容位置不变,但是在移动端就会中断滚动惯性。

    有什么解决办法吗?

    1 replies    2022-07-05 23:31:43 +08:00
    liushuigs
        1
    liushuigs  
       Jul 5, 2022
    可以试试 content-visibility: auto ,就是兼容性不一定那么好。这是个示例: https://runjs.work/#/projects/37c11589f7394d36
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5772 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 03:28 · PVG 11:28 · LAX 20:28 · JFK 23:28
    ♥ Do have faith in what you're doing.