-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.js
More file actions
46 lines (40 loc) · 1.35 KB
/
action.js
File metadata and controls
46 lines (40 loc) · 1.35 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
35
36
37
38
39
40
41
42
43
44
let yDir = "rotateX"
document.addEventListener("mousemove", function (event) {
const x = event.pageX
const y = event.pageY
const midX = x - window.innerWidth / 2
const midY = y - window.innerHeight / 2
const intensity = 3
const speed = ((2/1+Math.exp(-1*intensity*midY)))-1
const box = document.querySelector("section")
box.style.transform = "rotateX("+ midY + "deg)"
const numFaces = 8
const faceIndex = (Math.round(midY * speed * numFaces / 360) + numFaces) % numFaces
box.querySelectorAll("a.face").forEach((face, index) => {
if (index === faceIndex) {
face.style.backgroundColor = "#eee"
face.style.zIndex = 1
} else {
face.style.backgroundColor = "black"
face.style.zIndex = 0
}
})
// end of carousel rotation
// start click on div.face
// function click(x,y){
// const centerX = offset.left + width / 2;
// const centerY = offset.top + height / 2;
// var ev = document.createEvent("MouseEvent");
// var el = document.elementFromPoint(x,y);
// ev.initMouseEvent(
// "click",
// true /* bubble */, true /* cancelable */,
// window, null,
// x, y, centerX, centerY, /* coordinates */
// false, false, false, false, /* modifier keys */
// 0 /*left*/, null
// );
// el.dispatchEvent(ev);
// }
// end of click on div.face
})