Skip to content

Commit 6e377ee

Browse files
committed
feat: add scrolling with lentis
1 parent a0f53fe commit 6e377ee

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/app/app.component.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { RouterOutlet } from '@angular/router';
3+
import { ScrollService } from '@services/scroll.service';
34

45
@Component({
56
selector: 'app-root',
67
imports: [RouterOutlet],
78
templateUrl: './app.component.html',
89
styleUrl: './app.component.scss',
910
})
10-
export class AppComponent {}
11+
export class AppComponent implements OnInit {
12+
constructor(private scrollService: ScrollService) {}
13+
14+
ngOnInit() {
15+
this.scrollService.initLenis();
16+
}
17+
}

src/services/scroll.service.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { ScrollService } from './scroll.service';
4+
5+
describe('ScrollService', () => {
6+
let service: ScrollService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(ScrollService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});

src/services/scroll.service.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Injectable, NgZone } from '@angular/core';
2+
import Lenis from 'lenis';
3+
4+
@Injectable({
5+
providedIn: 'root',
6+
})
7+
export class ScrollService {
8+
private lenis!: Lenis;
9+
10+
constructor(private ngZone: NgZone) {}
11+
12+
initLenis() {
13+
this.ngZone.runOutsideAngular(() => {
14+
this.lenis = new Lenis({
15+
autoRaf: true,
16+
});
17+
});
18+
}
19+
}

0 commit comments

Comments
 (0)