Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!