Optimized code (significantly)
This commit is contained in:
1 parent
5fbb41c477
commit
a4b69c5b9a
31 files changed
+343
-441
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
|
||||
import {isPlatformBrowser} from '@angular/common';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class VantaBackgroundService {
|
||||
private vantaEffect: Map<string, any> = new Map();
|
||||
|
||||
constructor(
|
||||
@Inject(PLATFORM_ID) private platformId: Object,
|
||||
) {}
|
||||
|
||||
initVanta(elementId: string, options?: any) {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (element && !this.vantaEffect.has(elementId)) {
|
||||
(window as any).VANTA.NET({
|
||||
el: element,
|
||||
mouseControls: false,
|
||||
touchControls: false,
|
||||
gyroControls: false,
|
||||
scale: 1.0,
|
||||
scaleMobile: 1.0,
|
||||
points: 20.0,
|
||||
maxDistance: 25.0,
|
||||
spacing: 18.0,
|
||||
showDots: false,
|
||||
minWidth: window.innerWidth,
|
||||
minHeight: window.innerHeight,
|
||||
...(options || {}),
|
||||
});
|
||||
element.style.position = 'fixed';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resizeVanta(elementId: string): void {
|
||||
const effect = this.vantaEffect.get(elementId);
|
||||
if (effect) {
|
||||
effect.resize();
|
||||
}
|
||||
}
|
||||
|
||||
destroyVanta(elementId: string): void {
|
||||
const effect = this.vantaEffect.get(elementId);
|
||||
if (effect) {
|
||||
effect.destroy();
|
||||
this.vantaEffect.delete(elementId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user