Skip to content

Commit 8008df8

Browse files
committed
new scripts ready for born
1 parent 84b0a93 commit 8008df8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

parallax.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const parallax_el = document.querySelectorAll(".parallax");
2+
3+
let xValue = 0, yValue = 0;
4+
let rotateDegree = 0;
5+
6+
function update(cursorPosition) {
7+
parallax_el.forEach((el)=> {
8+
let speedx = el.dataset.speesx;
9+
let speedy = el.dataset.speesy;
10+
let speedz = el.dataset.speesz;
11+
let rotateSpeed = el.dataset.rotation;
12+
13+
let isInLeft = parseFloat(getComputedStyle(el).left) < window.innerWidth / 2 ? 1 : -1;
14+
let zValue = (cursorPosition - parseFloat(getComputedStyle(el).left)) * isInLeft * 0.1;
15+
16+
el.style.transform = `perspective(1500px) translateZ(${zValue * speedz}px) rotateY(${rotateDegree * rotateSpeed}deg) translateX(calc(-50% + ${-xValue * speedx}px)) translateX(calc(-50% + ${yValue * speedy}px))`;
17+
});
18+
}
19+
20+
update(0);
21+
22+
window.addEventListener("mousemove", (e) => {
23+
xValue = e.clientX - window.innerWidth / 2;
24+
yValue = e.clientY - window.innerHeight / 2;
25+
26+
rotateDegree = (xValue / (window.innerWidth / 2)) * 20;
27+
28+
update(e.clientX);
29+
});

0 commit comments

Comments
 (0)