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

156
Visualizações
jQuery scroll through sections not working

I'm trying to implement a feature where if the user scrolls his mousewheel, it scrolls down to the next section, and when they scroll again, it scrolls to the next section again. Here is an example: https://dolomiti.lefayresorts.com/en

For some reason my code doesn't work. Here is my code:

        var justscrolled = false;
        
        function scrollUp(){
            if(scrollPos > 0){
                scrollPos--;
                scrollToSection(scrollPos);
            }
        }
        
        function scrollDown(){
            if(scrollPos < maxScroll){
                scrollPos++;
                scrollToSection(scrollPos);
            }
        }
        
        function scrollToSection(index){
            justscrolled = true;
            var to = $("#section" + index).offset().top;
            console.log(index);
            console.log(to);
            $(document).scrollTop(to);
        }
        
        $(window).bind('mousewheel', function(event) {
            if (event.originalEvent.wheelDelta >= 0) {
                if(justscrolled){
                    justscrolled = false;
                    console.log("A");
                }
                else{
                    scrollUp();
                    console.log("B");
                }
            }
            else {
                console.log("downscroll");
                if(justscrolled){
                    console.log("A");
                    justscrolled = false;
                    
                }
                else{
                    console.log("B");
                    scrollDown();
                    
                }
                
            }
        }); 

When I scroll, the console logs that the scroll function worked, and I can see some flickering on my page when I scroll, but for some reason it doesn't actually scroll to the different sections.

Here is the full html file that you can test and see that it is not working: https://pastebin.com/EuGS5G2a

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