diff --git a/src/App.tsx b/src/App.tsx index 480b782..67a0869 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,25 +1,22 @@ import React from 'react' + import AnimatedBackground from './Components/AnimatedBackground' import Cursor from './Components/Cursor' +import Parallax from './Components/Parallax' import Letters from './Screens/Letters' -import { useMousePosition } from './util' export const Duration = 4000 const App: React.FC = () => { - const mouse = useMousePosition() - - const convertToDeg = (current: number, factor: number) => `${(.5 - current) * factor}deg` - return
-
-

- -

-
+ +
+

+ +

+
+
@@ -28,7 +25,7 @@ const App: React.FC = () => { diff --git a/src/Components/Parallax.tsx b/src/Components/Parallax.tsx new file mode 100644 index 0000000..f2951d3 --- /dev/null +++ b/src/Components/Parallax.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import { useMousePosition, useOrientation } from '../util' + +type RenderProps = { + x: string, + y: string +} + +const Render: React.FC = React.memo(({ children, x, y }) =>
+ {children} +
) + +const Parallax: React.FC = ({ children }) => { + + const orientation = useOrientation(true) + const mouse = useMousePosition() + const convertToDeg = (current: number, factor: number) => `${((.5 - current) * factor).toFixed(2)}deg` + + const orientationFactor = 3 + const x = orientation ? Math.min(orientation.x / orientationFactor, 1) : mouse.relative.x + const y = orientation ? Math.min(orientation.y / orientationFactor, 1) : mouse.relative.y + + return + {children} + +} + +export default Parallax \ No newline at end of file