【问题标题】:react-transition-group/react-router jumps to top of window on route changereact-transition-group/react-router 在路由更改时跳转到窗口顶部
【发布时间】:2019-01-13 16:04:10
【问题描述】:

https://www.wealthsimple.com/en-ca/culture/

如果您在内部页面上滚动任意数量并导航到另一个页面,它会快速跳转到页面顶部,然后进行页面转换。

我有转换容器作为 pos:ab。任何想法为什么会发生这种情况?

【问题讨论】:

    标签: reactjs gatsby react-transition-group


    【解决方案1】:

    如果其他人有这个问题,这就是我登陆的内容。当节点退出时,只需收集滚动位置并将其锁定到位。

    <TransitionGroup>
      <CSSTransition
        key={location.pathname}
        classNames="anim"
        timeout={{ enter: 700, exit: 700 }}
        onExit={node => {
          node.style.position = "fixed";
          node.style.top = -1 * window.scrollY + "px";
        }}
      >
        <TransitionHandler location={location}>
          <div>{children()}</div>
        </TransitionHandler>
      </CSSTransition>
    </TransitionGroup>
    

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 2018-02-10
      • 2019-05-31
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      相关资源
      最近更新 更多