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

300
Visualizações
After preventing the default scroll event, scrollIntoView(); doesn't work Properly on Firefox desktop?

In my scenario the code should prevent the the default scroll event and use scrollIntoView() to move the user to a specific section according to the scroll direction.

https://stackoverflow.com/a/4770179/9164633 I used this method to prevent the scroll default event.
And I detect the direction like so,

preventDefault(e) {
  e.preventDefault(); 
  if(this.waiting == false && this.forceInitialScroll != true) {
    if(e.deltaY && e.deltaY > 7) {
      this.scrollDirection = 'down';
        this.checkScroll()
    }else if(e.deltaY && e.deltaY < -7) {
      this.scrollDirection = 'up';
        this.checkScroll()
    }else {
      
    }
  }
},

and Im pretty sure that both are working fine.

After preventing the scroll and detecting the scroll direction I try to scroll the user to the section like so,

checkScroll() {
     let element;
     if(this.scrollDirection == 'down' && this.scrollIndex != 4 ) {
       element = document.getElementById(`section-${this.scrollIndex+1}`);
     }else if(this.scrollDirection == 'up' && this.scrollIndex != 0) {
       element = document.getElementById(`section-${this.scrollIndex-1}`);
     } 
     this.waiting = true;
     if(element) {
       console.log(element)
       element.scrollIntoView({
         behavior: 'smooth',
         block: 'center',
       })
     }
     setTimeout(() => {
       if(this.waiting == true) {
         this.waiting = false;
         this.scrollDirection = null;
       }
     }, 450)
   },

this.waiting is used to prevent the user form scrolling more than one section at a time.
On firefox the browser doesnt scroll the user properly though its working fine on chrome.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Apparently Firefox's behavior with event.preventDefault() was that it blocked any kind of user scrolling and even the js manual scrolling.

The problem in my case was solved by hiding the scroll in css instead of js by using overflow: hidden; and then controlling the scroll manually instead of preventing the default behavior.

about 4 years ago · Juan Pablo Isaza Relatório
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