-
-
Notifications
You must be signed in to change notification settings - Fork 98
Smooth Scroll
Murhaf Sousli edited this page Jan 28, 2024
·
8 revisions
Smooth scroll feature is built-in NgScrollbar
component, but if you like to use this feature outside NgScrollbar
component, then use SmoothScroll
directive which is available independently and it allows you to use smooth scroll functions on any scrollable element.
The package provides:
-
SmoothScroll
a directive for template usage -
SmoothScrollManager
a service for code usage
Import SmoothScroll
in your component the use the directive on your scrollable element
@Component({
standalone: true,
selector: 'my-app',
imports: [SmoothScroll],
template: `
<div smoothScroll #scrollable="smoothScroll" class="scrollable-container">
<div>{{scrollableContent}}</div>
</div>
<button (click)="scrollable.scrollTo({ bottom: 0, duration: 500 })">Scroll to bottom</button>
`
})
@Component({...})
export class FooComponent {
// A reference to the smooth scroll service
readonly smoothScroll: SmoothScrollManager = inject(SmoothScrollManager);
// A reference to a scrollable element (in this example it is the host element)
readonly scrollableElement: HTMLElement = inject(ElementRef).nativeElement;
scrollToTop(): void {
this.smoothScroll.scrollTo(this.scrollableElement, { top: 0, duration: 800 });
}
}
See all ScrollTo Functions.
Become a sponsor and get your logo on our README on GitHub and the front page of https://ngx-scrollbar.netlify.com/.
Become a backer and get your logo on our README on GitHub.
Latest version (v15)
Addons:
Older version (v13)
- Demo for v13
- Usage
- Styling
- Global Options
- Pointer Events
- Scroll Event
- Updated Event
- Smooth Scroll Functions
- Performance tweak
- Integration
- Reached events