forked from starifiedmc/modernclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (55 loc) · 1.78 KB
/
script.js
File metadata and controls
59 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { createApp } = Vue;
createApp({
data() {
return {
ready: false,
openDropdown: false,
buildOptions: [
{ value: 'js', label: 'JavaScript Build' },
{ value: 'wasm', label: 'WASM Build' }
],
selectedBuild: { value: 'wasm', label: 'WASM Build' },
};
},
methods: {
selectBuild(option) {
this.selectedBuild = option;
this.openDropdown = false;
},
launchSelectedBuild() {
const route = this.selectedBuild.value === 'wasm' ? './wasm/' : './js/';
window.location.assign(route);
},
onMouseMove(event) {
const w = window.innerWidth || 1;
const h = window.innerHeight || 1;
this._targetX = event.clientX / w;
this._targetY = event.clientY / h;
}
},
mounted() {
requestAnimationFrame(() => { this.ready = true; });
// Smooth parallax — lerp current position toward mouse target each frame,
// matching the lazy inertia of the in-game main menu background.
let curX = 0.5, curY = 0.5;
this._targetX = 0.5;
this._targetY = 0.5;
const bgEl = document.querySelector('.bg-image');
const LERP = 0.055; // lower = more lag, higher = snappier
const MAX_X = 28, MAX_Y = 22;
const tick = () => {
curX += (this._targetX - curX) * LERP;
curY += (this._targetY - curY) * LERP;
const tx = (curX - 0.5) * MAX_X;
const ty = (curY - 0.5) * MAX_Y;
if (bgEl) bgEl.style.transform = `translate(${tx}px, ${ty}px) scale(1.15)`;
requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
document.addEventListener('click', (e) => {
const dropdown = document.querySelector('.dropdown');
if (!dropdown) return;
if (!dropdown.contains(e.target)) this.openDropdown = false;
});
}
}).mount('#app');