The issue with Framer Motion's scrollYProgress not updating

Currently, I am working on a project that involves Framer Motion and Next.js. In my implementation, I am utilizing the Framer motion useScroll hook to keep track of the user's scroll activity on the page. However, it seems like the scroll tracking functionality is not updating as expected. Despite referring to the framer-motion documentation and following their provided examples, I seem to have missed something crucial in my code. Consequently, I am struggling to pinpoint the issue with my implementation. Any assistance or insight would be greatly appreciated.

Here is a snippet of my code:


const History = () => {
  const targetRef = useRef(null);
  const { scrollYProgress } = useScroll({
    target: targetRef,
  });

  console.log(scrollYProgress);

  const x = useTransform(scrollYProgress, [0, 1], ["1%", "-95%"]);

  return (
    <div>
      <Head>
        <title>매니지온 | History</title>
      </Head>
      <div>
        <h3 className="text-[2.3rem] lg:text-[2.625rem] font-[700] text-center mt-[5rem] w-full tracking-tighter">
          History
        </h3>
        <p className="text-[1rem] md:text-[1.8rem] lg:text-[2.0625rem] text-[#1f1f1f] mx-auto mt-[1rem] mb-[7rem] xl:mt-[5rem] xl:mb-[9.375rem] ">
          Title Main
          <span
            className="bg bg-no-repeat bg-center "
            style={{
              backgroundImage: "url(/images/sub/gr-underline02.png)",
              backgroundSize: "100%",
              backgroundPosition: "bottom",
            }}
          >
            Lorem ipsum dolor, sit amet consectetur adipisicing elit. Magnam
            voluptas illo recusandae eaque reiciendis. Illum repellendus harum
            dicta maxime placeat reiciendis. Dolore?
          </span>
          Lorem ipsum dolor sit, amet consectetur adipisicing elit. Voluptate
          facilis officia ut!
        </p>
      </div>
      <div ref={targetRef} className="relative h-[300vh] bg-neutral-900">
        <p className="absolute top-[10%] font-[700] left-6 md:hidden">
          <ArrowBackIcon /> Swipe Left
        </p>
        <div className="sticky top-0 flex h-screen items-center overflow-hidden">
          <motion.div style={{ x }} className="flex gap-4">
            {cards.map((card) => {
              return <Card card={card} key={card.id} />;
            })}
          </motion.div>
        </div>
      </div>
      <div className="h-[10vh] bg-red-500">Footer</div>
    </div>
  );
};

Repository: For more details, visit this git repository

I am attempting to utilize useScroll along with useTransform to create a horizontally scrollable container similar to this Sample

Answer №1

Your application is facing two distinct issues.

  1. You have restricted the height of html, body, and the root div to 100vh in a few places. Due to these modifications, there appears to be no scrolling on your page from the perspective of Framer Motion. To rectify this, you will need to eliminate those restrictions and ensure that your body is scrollable.

  2. In the useScroll function, it is imperative to specify the offset parameter as well. According to the Framer Motion documentation, this parameter dictates how Framer Motion should monitor intersection. It should be set to

    ["start start", "end end"]
    . This setting indicates that Framer Motion will commence tracking when the top side (i.e., the "start") of the viewport intersects with the top side of your target. At this point, the value of scrollYProgress will be 0 and will gradually increase as you scroll. Conversely, "end end" signifies that once the bottom side of the target element aligns with the viewport, the scroll tracking will cease, and the scrollYProgress value will reach 1.

I have submitted a pull request to your repository; feel free to review it to observe how these adjustments are reflected in the code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React function failing to utilize the latest state

I'm facing an issue with my handleKeyUp function where it doesn't seem to recognize the updated state value for playingTrackInd. Even though I update the state using setPlayingTrackInd, the function always reads playingTrackInd as -1. It's p ...

Encountered an issue when attempting to send data using this.http.post in Angular from the client's perspective

Attempting to transfer data to a MySQL database using Angular on the client-side and Express JS on the server-side. The post function on the server side works when tested with Postman. Here is the code snippet: app.use(bodyParser.json()); app.use(bodyPa ...

Issue with prop type: MUI - experiencing a warning while using ReactJS with MUI?

Upon attempting to open the datepicker by clicking on the icon, I encounter the following warning. Here is the code snippet where the error occurs: const DatePickerTextField = React.forwardRef((props: TextFieldProps, ref) => { const theme = useTheme() ...

The culprit behind Angular 11 app error: Unidentified router outlet triggering 'No routes match' issue

In my Angular 11 application, I am utilizing a named router-outlet. The setup in my app.component.html file looks like this: <ng-container *ngIf="showGeneric"> <router-outlet name="general"> </router-o ...

In TypeScript, the 'fs' module can be imported using the syntax `import * as fs from "

import * as fs from "fs"; const image1 = Media.addImage(document, fs.readFileSync("new.png")); Here is the configuration from my tsconfig.json: "compileOnSave": false, "compilerOptions": { "importHelpers": true, "outDir": "./dist/out-tsc", ...

Seeking guidance for the Angular Alert Service

I'm relatively new to using Angular and I'm struggling to determine the correct placement for my AlertService and module imports. Currently, I have it imported in my core module, which is then imported in my app module. The AlertService functions ...

A step-by-step guide on how to access the version number in an Angular (v4+) application from the package

Currently, I am attempting to retrieve the version number of my Angular application from package.json where it is stored. Most resources recommend using require to load the JSON file like so: var pckg = require('../../package.json'); console.log ...

Next JS encountered an error - Error [ERR_HTTP_HEADERS_SENT]: It is not possible to set headers after they have already been sent to the

Having crafted a serverless application using next.js, Vercel, and Google Sheets to store customer contact data, I encountered an issue post-deployment. While my application works flawlessly locally, after deployment, I started receiving the following erro ...

Hear and register keypress in Angular service

I offer a dialog service Check it out below @Injectable() export class HomeDialogService { public constructor(private readonly dialogService: DialogService, private readonly userAgent: UserAgentService) {} @HostListener('document:keydown.escape ...

Issue encountered in NestJS/TypeORM: Unable to modify the property metadata of #<Repository> as it only has a getter method

When attempting to launch my nestjstutorial app, I encountered the following error message. The backend is connected to a PostgreSQL database. TypeError: Cannot set property metadata of # which has only a getter at EntityManager.getCustomRepository (D:&b ...

Unable to locate repository instance while routing in the Express REST API

Can you please assist me with my routing issue? I am attempting to develop a REST API using TypeScript and the repository pattern in Node.js (express). I have created two generic classes, BaseRepository and BaseController, which handle basic CRUD transact ...

Steps for generating a fresh type denotation from a value within an object

Is it possible to create a new type alias based on an object's values? const test = { 'a': ['music','bbq','shopping'], 'b': ['move','work'] }; How can we extract this information f ...

`express-validator version 4 is not functioning as expected`

Trying to implement input validation using express-validator v4.3.0 for my express routes, but despite following the documentation, I am unable to get it working correctly. It seems to not detect any errors and also gets stuck in the route. Could it be tha ...

What is the reason for the distinction between {[x: string]: this} and Record<string, this> in TypeScript class member definitions?

Context Recently, I inquired about declaring a class member that is a function with covariant parameters related to the class, and it was suggested to utilize the polymorphic this type which proved to be a perfect solution. However, when implementing thi ...

Despite providing a type, Typescript continues to display an error claiming that the property 'children' does not exist on the type 'FC<ProvidersProps>'

I have set up the props interface, but I am still encountering an error. Property 'children' does not exist on type 'FC'. 'use clilent' import React, { FC, ReactNode } from 'react' import { Toaster } from 'rea ...

Interface specifying a React.ref property

When attempting to use a string as the ref, I encountered a warning when trying to access ref?.current Property 'current' does not exist on type 'string' What should be used for the ref prop in the interface? I am uncertain of the upfr ...

When the first argument is missing, using a recursive constraint default can result in the incorrect inference of the second argument, especially when both arguments share the same generic

Currently, I am developing a TypeScript implementation of a recursive binary search tree (BST) data structure using generic constraints. In order to establish a default for the recursive generic variable T without directly using it in the default declarati ...

The text cycling component in Next.js remains stagnant and never refreshes

I've encountered a challenge while working on a component that I initially thought would be straightforward: it's supposed to take an array of strings and update the text inside the div of the component every three seconds with the next item in t ...

What is the best way to create props that can accommodate three distinct types of functions in TypeScript?

I have been encountering a problem with the last function in my props interface that is supposed to support 3 different types of functions throughout the application. Despite adding parentheses as requested, I am still facing errors. // In Parent compon ...

Issue with Displaying Local Server Image in Angular 2 HTML

I am facing an issue with my Angular 2 Application. It retrieves items from a local database where the server stores the image of the item and the database stores the path to that image stored on the server. While I can retrieve all the items without any p ...