Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
page navigation with window wheel event in web (ref website : https://www.laundrygo.com) - react, useState, useEffect

I've been trying to create a web page with a window wheel event to make it work like (ref : https://www.laundrygo.com). As you may check on the ref website, if user scrolls down or up, the page very naturally moves.

To benchmark this, I used 'window.addEventListner("wheel", function), useState & UseEffect in React and boolean Flag'. However, it takes all the wheel events(4~10 times with a single scrolling...) within very short period of time. As a result of it, the page moves up & down two~four times(to the bottom or top) in a row, Which is not what i expect at all.... Even sometimes it moves to the opposite side.

I am adding up my code & screenshots below. Please review and give me some insights to solve this issue.

FYI:

  1. I'm Using: React, JS.
  2. I tried lodash debounce & throttle. None of them worked out.
  3. It has totally 6 pages including splash & footer page.
    const [currentPage, setCurrentPage] = useState(1);
    const [isLoading, setIsLoading] = useState(false);

    const moveDown = () => {
        setCurrentPage(currentPage + 1);
        loadingController();
    };

    const moveUp = () => {
        setCurrentPage(currentPage - 1);
        loadingController();
    };

    const loadingController = () => {
        setTimeout(() => {
            setIsLoading(false);
        }, 1000);
    }

    const wheelEventCaller = () => {
        if (!isLoading) {
            setIsLoading(true);
            window.addEventListener("wheel", (e) => {
                e.preventDefault();
                if (e.deltaY > 500) {
                    if (currentPage >= 6) return;
                    moveDown();
                } else if (e.deltaY < 500) {
                    if (currentPage <= 1) return;
                    moveUp();
                }
            }, {passive: false});
        } else {
            return;
        }
    };

    useEffect(() => {
        wheelEventCaller();
    }, [isLoading, currentPage]);

enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda