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

513
Views
Angular scrollPositionRestoration without animation / smooth scrolling?

Using scrollPositionRestoration: 'enabled' for the RouterModule is really a nice feature but how to disable the scroll animation / smooth scrolling so it snaps to the position?

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      scrollPositionRestoration: 'enabled',
    }),
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {
}

Background: Having smooth scrolling does not feel like navigating a "normal" website because normally if navigating back and forth there is no smooth scrolling.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The issue wasn't Angular, instead Bootstrap has set CSS smooth-scrolling to smooth.

Disabled it by $enable-smooth-scroll: false;

over 4 years ago · Santiago Trujillo Report

0

There is an open issue at Angular's github about scrollPositionRestoration

I tried to make an alternative, I hope it helps you:

https://stackblitz.com/edit/angular-ivy-jxm1mu?file=src%2Fapp%2Fapp.module.ts

I couldn't reproduce the navigate back behaviour with stackblitz because the app reloads.

When the user scrolls, save the scroll Y position and then, when the router emits the scrolling event, you make it not smooth.

window.scrollTo doc says that there is a value behavior: instant, I used auto because linter marked it as a error, so maybe it is not widely supported.

over 4 years ago · Santiago Trujillo Report

0

I was having the same problem. I tried using Mick's solution of changing the variable in bootstrap's "scss/_variables.scss" file but it didn't work out for me (Plus since it was in the node_modules which we don't share while the code is committed, any changes there wouldn't do any good as well, I guess). So I tried over riding in styles.css as:-

html {

scroll-behavior: auto !important

}

And it worked for me. I was having multiple CSS files in the global context for the project and maybe that's why the bootstrap variable change didn't work for me because other files may have interfered as well.

over 4 years ago · Santiago Trujillo 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!