Skip to content

Commit 12737ff

Browse files
committed
Changed stuff for performance optimization
1 parent 515d41e commit 12737ff

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@omnedia/ngx-globe",
33
"description": "A simple component library to create a container with an animated and interactive globe.",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"peerDependencies": {
66
"@angular/common": "^18.2.0",
77
"@angular/core": "^18.2.0",

src/lib/ngx-globe.component.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
9191
pointerInteractionMovement = 0;
9292
private globeRotation = 0;
9393

94+
private intersectionObserver?: IntersectionObserver;
95+
private isAnimating = false;
96+
9497
ngAfterViewInit(): void {
9598
this.initGlobe();
99+
100+
this.intersectionObserver = new IntersectionObserver(([entry]) => {
101+
this.renderContents(entry.isIntersecting)
102+
})
103+
this.intersectionObserver.observe(this.globeCanvas.nativeElement);
96104
}
97105

98106
ngOnDestroy(): void {
@@ -105,6 +113,18 @@ export class NgxGlobeComponent implements AfterViewInit, OnDestroy {
105113
this.globeCanvas.nativeElement.height = this.globeSize;
106114
}
107115

116+
renderContents(isIntersecting: boolean) {
117+
if (isIntersecting && !this.isAnimating) {
118+
this.isAnimating = true;
119+
120+
this.globe?.toggle(true);
121+
} else if (!isIntersecting && this.isAnimating) {
122+
this.isAnimating = false;
123+
124+
this.globe?.toggle(false);
125+
}
126+
}
127+
108128
initGlobe(): void {
109129
let phi = this.cobeOptions.phi;
110130
let cobeOptions = {

0 commit comments

Comments
 (0)