-
Notifications
You must be signed in to change notification settings - Fork 0
/
script copy new.js
253 lines (182 loc) · 6.59 KB
/
script copy new.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//
//
// Holo script for movement and everything START
//
//
const initialStyles = new WeakMap();
function saveInitialStyles(card) {
// Initialwerte sichern
const computedStyle = window.getComputedStyle(card);
initialStyles.set(card, {
transform: computedStyle.transform || 'rotateX(0deg) rotateY(0deg) scale(1)',
mx: computedStyle.getPropertyValue('--mx').trim() || '0%',
my: computedStyle.getPropertyValue('--my').trim() || '0%',
s: computedStyle.getPropertyValue('--s').trim() || '1',
o: computedStyle.getPropertyValue('--o').trim() || '1',
pos: computedStyle.getPropertyValue('--pos').trim() || '0% 0%',
posx: computedStyle.getPropertyValue('--posx').trim() || '0%',
posy: computedStyle.getPropertyValue('--posy').trim() || '0%',
hyp: computedStyle.getPropertyValue('--hyp').trim() || '0',
galaxybg: computedStyle.getPropertyValue('--galaxybg').trim() || 'initial',
});
}
function OrientCard(e) {
const card = e.currentTarget;
const rect = card.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const mvX = e.clientX - centerX;
const mvY = e.clientY - centerY;
const maxTilt = 15;
const Xdeg = clamp(-mvY / (rect.height / 2) * maxTilt, -maxTilt, maxTilt);
const Ydeg = clamp(mvX / (rect.width / 2) * maxTilt, -maxTilt, maxTilt);
gsap.to(card, {
duration: 0.5,
transform: `rotateX(${Xdeg}deg) rotateY(${Ydeg}deg) scale(1.05)`,
"--mx": `${40 - (Ydeg * 2.5)}%`,
"--my": `${5 + Xdeg / 2}%`,
"--pos": `${Ydeg * 2.5}% ${Xdeg * 0.5}%`,
"--posx": `${50 + Ydeg / 2 + Xdeg * 0.5}%`,
"--posy": `${50 + Xdeg / 2 + Ydeg / 2}%`,
"--hyp": `${Math.min(Math.max(Math.sqrt((mvX * mvX) + (mvY * mvY)) / 50, 0), 1)}`,
ease: "power4.out",
overwrite: true // Overwrite previous GSAP animations
});
}
function handleMouseLeave(e) {
const card = e.currentTarget;
const initial = initialStyles.get(card);
if (initial) {
gsap.to(card, {
duration: 0.5,
transform: initial.transform,
"--mx": initial.mx,
"--my": initial.my,
"--pos": initial.pos,
"--posx": initial.posx,
"--posy": initial.posy,
"--hyp": initial.hyp,
"--scale": initial.s,
ease: "power4.inOut",
overwrite: true // Overwrite previous GSAP animations
});
}
}
function clamp(value, min = -20, max = 20) {
return Math.min(Math.max(value, min), max);
}
document.addEventListener("DOMContentLoaded", () => {
if (window.DeviceOrientationEvent && 'ontouchstart' in window) {
document.getElementById('mouseMoveLabel').innerHTML = 'Phone move';
window.addEventListener('deviceorientation', orientationhandler, false);
window.addEventListener('MozOrientation', orientationhandler, false);
} else {
document.getElementById('mouseMoveLabel').innerHTML = 'Mouse move';
}
document.querySelectorAll(".card").forEach(card => {
saveInitialStyles(card);
card.addEventListener('mousemove', e => {
document.querySelector('.PNL_Infos').innerHTML = `M.x:${e.clientX}px; M.y:${e.clientY}px;`;
OrientCard(e);
});
card.addEventListener('mouseleave', handleMouseLeave);
});
});
function orientationhandler(event) {
const alpha = event.alpha; // Rotation um die Z-Achse (0–360 Grad)
const beta = event.beta; // Neigung um die X-Achse (-180 bis 180 Grad)
const gamma = event.gamma; // Neigung um die Y-Achse (-90 bis 90 Grad)
gsap.to(".card", {
duration: 0.5,
transform: `rotateX(${beta}deg) rotateY(${gamma}deg) rotateZ(${alpha}deg)`,
ease: "power2.out",
overwrite: true // Overwrite previous GSAP animations
});
}
//
//
// Holo script for movement and everything ENDE
//
//
//
//
// FILTER JAVASCRIPT START
//
//
// Filter for PNL_ChooseCard -> Change all cards to X Image
// Update the image source for all cards based on input value
function changeCard(e) {
var cards = document.querySelectorAll(".card img");
Array.from(cards).forEach(card => {
card.setAttribute('src', e.value);
});
}
// Filter for PNL_options -> Which Holo do you want?
// Update the Holographic source for all cards based on input value
function adaptCardType(e) {
var cards = document.getElementsByClassName("card");
Array.from(cards).forEach(card => {
card.setAttribute('data-rarity', e.value);
});
}
// Filter for Sort by
document.addEventListener("DOMContentLoaded", function() {
const categoryFilter = document.getElementById('category-filter');
const cardGrid = document.querySelector('.card-grid');
categoryFilter.addEventListener('change', function() {
const selectedCategory = categoryFilter.value;
filterCards(selectedCategory);
});
function filterCards(category) {
const cards = Array.from(cardGrid.querySelectorAll('.holographic__section'));
cards.forEach(card => {
const cardCategory = card.querySelector('.card').getAttribute('data-category');
if (category === 'all' || cardCategory === category) {
card.style.display = '';
} else {
card.style.display = 'none';
}
});
}
});
// Filter for Grid-Layout Changer
document.addEventListener("DOMContentLoaded", function() {
// Get references to the buttons
const grid1Button = document.querySelector("button img[alt='Grid 1']").parentElement;
const grid2Button = document.querySelector("button img[alt='Grid 2']").parentElement;
const barsButton = document.querySelector("button img[alt='Grid 3']").parentElement;
// Get reference to the card grid
const cardGrid = document.querySelector(".card-grid");
// Set initial layout and active button
changeGridLayout(1); // Set layout-3 as the initial layout
// Add event listeners to the buttons
grid1Button.addEventListener("click", () => changeGridLayout(1));
grid2Button.addEventListener("click", () => changeGridLayout(2));
barsButton.addEventListener("click", () => changeGridLayout(3));
// Function to change grid layout
function changeGridLayout(layout) {
cardGrid.classList.remove("layout-1", "layout-2", "layout-3");
grid1Button.classList.remove("active");
grid2Button.classList.remove("active");
barsButton.classList.remove("active");
switch(layout) {
case 1:
cardGrid.classList.add("layout-1");
grid1Button.classList.add("active");
break;
case 2:
cardGrid.classList.add("layout-2");
grid2Button.classList.add("active");
break;
case 3:
cardGrid.classList.add("layout-3");
barsButton.classList.add("active");
break;
}
}
});
//
//
// FILTER JAVASCRIPT ENDE
//
//