Strange jumps in scrolling behavior in Nuxt 3
P粉885562567
P粉885562567 2024-03-25 23:22:30
0
1
458

So I configured the rouse.scrollBehaviour.ts file in Nuxt 3. as follows:

import { defineNuxtPlugin } from "#app";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.$router.options.scrollBehavior = (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    }
    return { left: 0, top: 0, behaviour: "smooth" };
  };
});

The problem is I think it's scrolling earlier than the page loads, so there's a weird jumping effect on the page.

Here is a video of the issue: https://user-images.githubusercontent.com/22452368/154849559-3974fc01-e265-486b-865b-55ee03053fa8.mp4

Can you help me see what's wrong here? Or is there a bug in Nuxt 3?

P粉885562567
P粉885562567

reply all(1)
P粉696146205

You can try the solution mentioned in nuxt question

// app/router.options.js
export default {
  scrollBehavior() {
    return { top: 0 }
  },
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template