-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (25 loc) · 1.11 KB
/
Copy pathapp.js
File metadata and controls
34 lines (25 loc) · 1.11 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
const track = document.getElementById("image-track");
window.onmousedown = e => {
track.dataset.mouseDownAt = e.clientX;
}
window.onmouseup = () => {
track.dataset.mouseDownAt = "0";
track.dataset.prevPercentage = track.dataset.percentage;
}
window.onmousemove = e => {
if(track.dataset.mouseDownAt === "0") return;
const mouseDelta = parseFloat(track.dataset.mouseDownAt) - e.clientX, maxDelta = window.innerWidth / 2;
const percentage = (mouseDelta / maxDelta) * -100,
nextPercentageUnbounded = parseFloat(track.dataset.prevPercentage) + percentage;
const nextPercentage = Math.max(Math.min(nextPercentageUnbounded, 0), -100);
track.dataset.percentage = nextPercentage;
// track.style.transform = `translate(${nextPercentage}%, -50%)`;
track.animate({
transform: `translate(${nextPercentage}%, -50%)`
}, {duration: 1200, fill: "forwards" });
for(const image of track.getElementsByClassName("image")) {
image.animate({
objectPosition: `${100 + nextPercentage}% center`
}, {duration: 1200, fill: "forwards" });
}
}