Skip to content

[Bug Report] Since v2.1.0, animations no longer work when navigating back between routes from the bottom of a page #177

@rylanharper

Description

@rylanharper

First of all, let me say thank you for the work/up-keep on this project, its one of my favorite Vue-related libraries and makes working with animations a breeze!

System info

  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.8.1
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: devtools, modules
  • Runtime Modules: @vueuse/nuxt@10.8.0, @vueuse/motion/nuxt@2.1.0
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-ydptdz?file=README.md

Describe the bug

Since the most recent update, I noticed when working on my portfolio that when I navigate to the bottom of a page and click the Next Project button, the following page's initial visibleOnce animation does not occur, nor does it occur when navigating manually between project routes from the bottom of a page and back. It only occurs when I navigate to a given page (or in my case project) from the top of the router view. This could be a router issue, although I am not sure.

To reliably demonstrate this, I created a the following Slackblitz.

  • Simply navigate to the bottom of the page, click the next page link (about page)
  • Then manually navigate back by clicking the browser arrows, and the bottom most animation (h2 element) will not appear. It will only appear when navigating to the given page from the top of the router and scrolling down to see it.

Additional context

This is a pretty common use-case since users most always navigate to the bottom of a given page and then click new link that takes them to the next page.

Not really sure what a quick fix for this is.. Even when using a useMotion composable within an onMounted hook for my project items it does not appear to work when navigating to a new project page from the bottom.

// project DOM refs
const projectItems = ref(null)
const animationReady = ref(false)

// Animation
const animate = (i) => ({
  initial: {
    y: 35,
    opacity: 0
  },
  visibleOnce: {
    y: 0,
    opacity: 1,
    transition: {
      type: 'spring',
      delay: 75 * i
    }
  }
})

// Init animation w/ useMotion
onMounted(() => {
  const items = projectItems.value

  if (items) {
    items.forEach((item, i) => {
      useMotion(item, animate(i))
    })
  }

  animationReady.value = true
})
</script>

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions