blob: 6afc20bebab8e4001313263bdf3d73586dd4afd3 (
plain) (
blame)
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
|
document.querySelector(".wrapper").style.opacity = 1;
let cards = document.querySelectorAll(".card");
cards.forEach((card, index) => {
card.style.zIndex = cards.length - index;
card.style.transform =
"scale(" + (20 - index) / 20 + ") translateY(-" + 30 * index + "px)";
card.style.opacity = (10 - index) / 10;
let hammer = new Hammer(card);
hammer.on("pan", (event) => {
if (event.deltaX === 0) return;
if (event.center.x === 0 && event.center.y === 0) return;
const xMulti = event.deltaX * 0.03;
const yMulti = event.deltaY / 80;
const rotate = xMulti * yMulti;
event.target.style.transform =
"translate(" +
event.deltaX +
"px, " +
event.deltaY +
"px) rotate(" +
rotate +
"deg)";
});
hammer.on("panend", (event) => {
const moveOutWidth = document.body.clientWidth;
const keep = Math.abs(event.deltax) < 80 || Math.abs(event.velocityX) < 0.5;
if (keep) {
event.target.style.transform = "";
} else {
event.target.style.opacity = 0;
const endX = Math.max(
Math.abs(event.velocityX) * moveOutWidth,
moveOutWidth
);
const toX = event.deltaX > 0 ? endX : -endX;
const endY = Math.abs(event.velocityY) * moveOutWidth;
var toY = event.deltaY > 0 ? endY : -endY;
var xMulti = event.deltaX * 0.03;
var yMulti = event.deltaY / 80;
var rotate = xMulti * yMulti;
event.target.style.transform =
"translate(" +
toX +
"px, " +
(toY + event.deltaY) +
"px) rotate(" +
rotate +
"deg)";
}
});
});
|