File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535ensureThreeGlobal ()
3636
3737const vantaGlobe = ref <HTMLElement | null >(null )
38-
39- useHead ({
40- script: [
41- {
42- async: true ,
43- src: " /scripts/vanta.globe.min.js" ,
44- defer: true ,
45- onload() {
46- applyVantaGlobe (vantaGlobe .value ! )
47- },
48- },
49- ],
50- })
38+ useVanta (" globe" , () => vantaGlobe .value ! )
5139 </script >
Original file line number Diff line number Diff line change @@ -34,17 +34,5 @@ import myceliumBg2 from "~/assets/images/mycelium_bg_2.svg"
3434ensureThreeGlobal ()
3535
3636const vantaDots = ref <HTMLElement | null >(null )
37-
38- useHead ({
39- script: [
40- {
41- async: true ,
42- src: " /scripts/vanta.dots.min.js" ,
43- defer: true ,
44- onload() {
45- applyVantaDots (vantaDots .value ! )
46- },
47- },
48- ],
49- })
37+ useVanta (" dots" , () => vantaDots .value ! )
5038 </script >
Original file line number Diff line number Diff line change 1+ export function useVanta ( type : "dots" | "globe" , el : ( ) => HTMLElement ) {
2+ useHead ( {
3+ script : [
4+ {
5+ async : true ,
6+ src : `/scripts/vanta.${ type } .min.js` ,
7+ defer : true ,
8+ onload ( ) {
9+ applyVanta ( type , el ( ) )
10+ } ,
11+ } ,
12+ ] ,
13+ } )
14+
15+ const script = document . querySelector ( `script[src="/scripts/vanta.${ type } .min.js"]` )
16+ if ( script ) {
17+ nextTick ( ( ) => {
18+ applyVanta ( type , el ( ) )
19+ } )
20+ }
21+ }
Original file line number Diff line number Diff line change 2323definePageMeta ({ middleware: " public" })
2424
2525ensureThreeGlobal ()
26- const vantaDots = ref <HTMLElement | null >(null )
2726
28- useHead ({
29- script: [
30- {
31- async: true ,
32- src: " /scripts/vanta.dots.min.js" ,
33- defer: true ,
34- onload() {
35- applyVantaDots (vantaDots .value ! )
36- },
37- },
38- ],
39- })
27+ const vantaDots = ref <HTMLElement | null >(null )
28+ useVanta (" dots" , () => vantaDots .value ! )
4029
4130const features = [
4231 {
Original file line number Diff line number Diff line change @@ -8,7 +8,16 @@ export function ensureThreeGlobal() {
88 return THREE
99}
1010
11- export function applyVantaDots ( el : HTMLElement ) {
11+ export function applyVanta ( type : "dots" | "globe" , el : HTMLElement ) {
12+ if ( type === "dots" ) {
13+ applyVantaDots ( el )
14+ }
15+ else if ( type === "globe" ) {
16+ applyVantaGlobe ( el )
17+ }
18+ }
19+
20+ function applyVantaDots ( el : HTMLElement ) {
1221 window ?. VANTA ?. DOTS ?.( {
1322 el,
1423 mouseControls : true ,
@@ -27,7 +36,7 @@ export function applyVantaDots(el: HTMLElement) {
2736 } )
2837}
2938
30- export function applyVantaGlobe ( el : HTMLElement ) {
39+ function applyVantaGlobe ( el : HTMLElement ) {
3140 window ?. VANTA ?. GLOBE ?.( {
3241 el,
3342 mouseControls : true ,
You can’t perform that action at this time.
0 commit comments