-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (37 loc) · 945 Bytes
/
script.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
const gallery = document.getElementById("gallery");
window.onmousemove = (event) => {
const mouse = {
x: event.clientX,
y: event.clientY
}
const percentage = {
x: mouse.x / window.innerWidth,
y: mouse.y / window.innerHeight
}
const pan = getPan(percentage)
gallery.animate({
transform: `translate(${pan.x}px, ${pan.y}px)`
}, {
duration: 4000,
fill: "forwards",
easing: "ease"
})
}
function getPan(percentage) {
const max = {
x: window.innerWidth - gallery.offsetWidth,
y: window.innerHeight - gallery.offsetHeight
}
const pan = {
x: max.x * percentage.x,
y: max.y * percentage.y
}
return pan
}
// Center pan on page load
const mid = {
x: 0.5,
y: 0.5
}
const start = getPan(mid)
gallery.style.transform = `translate(${start.x}px, ${start.y}px)`