在Next.js中,有没有办法确定是否使用了滚动架,即使使用了后纽按钮?

发布于 2025-01-29 06:22:10 字数 275 浏览 3 评论 0 原文

我正在使用 scrollrestoration Next.js的功能来恢复页面位置时按下返回按钮。问题是,它不会恢复该页面上旋转木马的水平滚动位置。因此,我创建了自己的会话变量来跟踪每个轮播的位置并在页面加载中还原它们。问题是,如果按下背面/向前按钮,我只想恢复这些滚动位置。如果有一个指标表明 scrollrestoration 在页面上使用了,则可以使用该页面,否则,如果有迹象表明该页面是使用也可以解决该页面的forward/back按钮访问的。

有什么想法吗?

I am using the scrollRestoration feature of Next.js to restore the page position when a back button is pressed. The problem, is that it doesn't restore the horizontal scroll position of the carousels on that page. So I have created my own session variables to track the position of each carousel and restore them on page load. The problem, is that I ONLY want to restore these scroll positions if the back/forward button was pressed. If there is an indicator that scrollRestoration was used on the page I could use that, otherwise, if there is an indication that the page was visited using the forward/back buttons that would also solve it.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦 2025-02-05 06:22:10

我已经弄清楚了如何确定是否为页面设置了卷轴。

React.useEffect(() => {
    const hasScrollHistory = sessionStorage.getItem(`__next_scroll_${window.history.state.idx}`);
    if (hasScrollHistory) {
        // do your restore logic here
    }
}, []);

i have figured out how to determine if scrollRestoration is set for a page.

React.useEffect(() => {
    const hasScrollHistory = sessionStorage.getItem(`__next_scroll_${window.history.state.idx}`);
    if (hasScrollHistory) {
        // do your restore logic here
    }
}, []);
烟酒忠诚 2025-02-05 06:22:10

从来没有这样做,但是我的本能是:

围绕框架的这种方式,但看起来下一步并不像您要寻找的东西。

Never done this but my instinct would be:

That kind of goes around the framework, but it doesn't look like Next exposes what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文