-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery.js
84 lines (70 loc) · 1.94 KB
/
gallery.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
let currentlySelected = 0;
const nodes = document.querySelectorAll(".gallery-img");
const prevBtn = document.querySelector(".prev");
const nextBtn = document.querySelector(".next");
function previous() {
nextBtn.disabled = false;
nodes[currentlySelected].classList.remove("active");
currentlySelected--;
nodes[currentlySelected].classList.add("active");
if (currentlySelected === 0) {
prevBtn.disabled = true;
}
}
function next() {
prevBtn.disabled = false;
nodes[currentlySelected].classList.remove("active");
currentlySelected++;
nodes[currentlySelected].classList.add("active");
if (currentlySelected + 1 === nodes.length) {
nextBtn.disabled = true;
}
}
function init() {
prevBtn.addEventListener("click", function() {
previous();
});
nextBtn.addEventListener("click", function(e) {
next();
});
}
init();
const { styler, spring, listen, pointer, value } = window.popmotion;
const heart1 = document.querySelector('.heart1');
const divStyler1 = styler(heart1);
const heartXY1 = value({ x: 0, y: 0 }, divStyler1.set);
listen(heart1, 'mousedown touchstart')
.start((e) => {
e.preventDefault();
pointer(heartXY1.get()).start(heartXY1);
});
listen(document, 'mouseup touchend')
.start(() => {
spring({
from: heartXY1.get(),
velocity: heartXY1.getVelocity(),
to: { x: 0, y: 0 },
stiffness: 200,
// mass: 1,
// damping: 10
}).start(heartXY1);
});
const heart2 = document.querySelector('.heart2');
const divStyler2 = styler(heart2);
const heartXY2 = value({ x: 0, y: 0 }, divStyler2.set);
listen(heart2, 'mousedown touchstart')
.start((e) => {
e.preventDefault();
pointer(heartXY2.get()).start(heartXY2);
});
listen(document, 'mouseup touchend')
.start(() => {
spring({
from: heartXY2.get(),
velocity: heartXY2.getVelocity(),
to: { x: 0, y: 0 },
stiffness: 200,
// mass: 1,
// damping: 10
}).start(heartXY2);
});