-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-vanilla.html
More file actions
172 lines (143 loc) · 4.05 KB
/
Copy pathtest-vanilla.html
File metadata and controls
172 lines (143 loc) · 4.05 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
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>holo</title>
<style>
/* body{
margin: 0;
background: #222;
overflow: hidden;
} */
.img-s6 {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
max-width: 90%;
max-height: 90%;
transition: opacity 0.2s ease;
opacity: 0;
will-change: opacity;
transition: opacity 0.15s linear;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
max-width: 90%;
max-height: 90%;
opacity: 0;
transition: opacity 0.15s linear;
will-change: opacity;
}
</style>
</head>
<body>
<section>
<img class="img-s6" src="img/2A3A9717.JPG" alt="">
<img class="img-s6" src="img/2A3A9718.JPG" alt="">
<img class="img-s6" src="img/2A3A9719.JPG" alt="">
<img class="img-s6" src="img/2A3A9720.JPG" alt="">
</section>
<!-- <script>
/*
const images = document.querySelectorAll(".img");
const minAngle = -70;
const maxAngle = 70;
const steps = images.length - 1;
window.addEventListener("deviceorientation", (evt) => {
const angle = evt.gamma;
const t = clamp(invLerp(minAngle, maxAngle, angle), 0, 1);
const scaled = t * steps;
const index = Math.floor(scaled);
const localT = scaled - index;
images.forEach(img => img.style.opacity = 0);
if (images[index]) {
images[index].style.opacity = 1 - localT;
}
if (images[index + 1]) {
images[index + 1].style.opacity = localT;
}
});
function invLerp(a, b, v) {
return (v - a) / (b - a);
}
function clamp(v, min, max) {
return Math.min(max, Math.max(min, v));
}
*/
const images = document.querySelectorAll(".img");
const steps = images.length - 1;
function updateFromT(t) {
const scaled = t * steps;
const index = Math.floor(scaled);
const localT = scaled - index;
images.forEach(img => img.style.opacity = 0);
if (images[index]) {
images[index].style.opacity = 1 - localT;
}
if (images[index + 1]) {
images[index + 1].style.opacity = localT;
}
}
// desktop
window.addEventListener("mousemove", e => {
const t = clamp(e.clientY / window.innerHeight, 0, 1);
updateFromT(t);
});
// mobile
window.addEventListener("deviceorientation", e => {
const minAngle = -70;
const maxAngle = 70;
const t = clamp((e.gamma - minAngle) / (maxAngle - minAngle), 0, 1);
updateFromT(t);
});
function clamp(v, min, max) {
return Math.min(max, Math.max(min, v));
}
</script> -->
<script>
const images = document.querySelectorAll(".img-s6");
const steps = images.length - 1;
// état
let targetT = 0;
let currentT = 0;
const smoothness = 0.1;
// init
images[0].style.opacity = 1;
function updateImages(t) {
const scaled = t * steps;
const index = Math.floor(scaled);
const localT = scaled - index;
// reset simple et fiable
images.forEach(img => img.style.opacity = 0);
if (images[index]) {
images[index].style.opacity = 1 - localT;
}
if (images[index + 1]) {
images[index + 1].style.opacity = localT;
}
}
function animate() {
currentT += (targetT - currentT) * smoothness;
updateImages(currentT);
requestAnimationFrame(animate);
}
// desktop
window.addEventListener("mousemove", e => {
targetT = clamp(e.clientX / window.innerHeight, 0, 1);
});
// mobile
window.addEventListener("deviceorientation", e => {
const minAngle = -70;
const maxAngle = 70;
targetT = clamp((e.gamma - minAngle) / (maxAngle - minAngle), 0, 1);
});
function clamp(v, min, max) {
return Math.min(max, Math.max(min, v));
}
animate();
</script>
</body>
</html>