File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments