-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathhoverCard.js
35 lines (27 loc) · 978 Bytes
/
hoverCard.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
let constrain = 5;
let mouseOverContainer = document.getElementById("ex1-layer");
function transforms(x, y, el) {
el.style.transform = '';
let box = el.getBoundingClientRect();
let calcX = -(y - box.y - (box.height / 2)) / (el.dataset.scale == 2 ? constrain * 2 : constrain);
let calcY = (x - box.x - ((box.width ? box.width : 71) / 2)) / (el.dataset.scale == 2 ? constrain * 2 : constrain);
if(box.width === 0) {
return `translate(35.5px) perspective(${94}px) ` +
`rotateX(${calcX}deg) ` +
`rotateY(${calcY}deg) translate(-35.5px)`;
}
return `perspective(${94}px) ` +
`rotateX(${calcX}deg) ` +
`rotateY(${calcY}deg)`;
};
//mousemove
function hoverCard(e) {
let target = e.target;
let position = [e.clientX, e.clientY, e.target];
target.style.transform = transforms.apply(null, position);
}
// mouseout
function noHoverCard(e) {
e.target.style.transform = '';
}
// onmousemove = 'hoverCard(event)' onmouseout = 'noHoverCard(event)'