mirror of
https://github.com/cupcakearmy/old.nicco.io.git
synced 2025-02-22 02:09:24 +00:00
move parallax to own component
This commit is contained in:
parent
035db48165
commit
6aec867420
15
src/App.tsx
15
src/App.tsx
@ -1,25 +1,22 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import AnimatedBackground from './Components/AnimatedBackground'
|
import AnimatedBackground from './Components/AnimatedBackground'
|
||||||
import Cursor from './Components/Cursor'
|
import Cursor from './Components/Cursor'
|
||||||
|
import Parallax from './Components/Parallax'
|
||||||
import Letters from './Screens/Letters'
|
import Letters from './Screens/Letters'
|
||||||
import { useMousePosition } from './util'
|
|
||||||
|
|
||||||
export const Duration = 4000
|
export const Duration = 4000
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
|
|
||||||
const mouse = useMousePosition()
|
|
||||||
|
|
||||||
const convertToDeg = (current: number, factor: number) => `${(.5 - current) * factor}deg`
|
|
||||||
|
|
||||||
return <div id="App">
|
return <div id="App">
|
||||||
<section id={'letters-container'} style={{
|
<Parallax>
|
||||||
transform: `rotateX(${convertToDeg(mouse.relative.y, 2)}) rotateY(${convertToDeg(mouse.relative.x, .5)})`,
|
<section id={'letters-container'}>
|
||||||
}}>
|
|
||||||
<h1>
|
<h1>
|
||||||
<Letters/>
|
<Letters/>
|
||||||
</h1>
|
</h1>
|
||||||
</section>
|
</section>
|
||||||
|
</Parallax>
|
||||||
|
|
||||||
<div id={'bg'}>
|
<div id={'bg'}>
|
||||||
<AnimatedBackground/>
|
<AnimatedBackground/>
|
||||||
@ -28,7 +25,7 @@ const App: React.FC = () => {
|
|||||||
<Cursor/>
|
<Cursor/>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<span>dev.</span>
|
<span>developer.</span>
|
||||||
<br/>
|
<br/>
|
||||||
<span>say <a href={'mailto:hi@nicco.io'}>hi@nicco.io</a></span>
|
<span>say <a href={'mailto:hi@nicco.io'}>hi@nicco.io</a></span>
|
||||||
</footer>
|
</footer>
|
||||||
|
31
src/Components/Parallax.tsx
Normal file
31
src/Components/Parallax.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useMousePosition, useOrientation } from '../util'
|
||||||
|
|
||||||
|
type RenderProps = {
|
||||||
|
x: string,
|
||||||
|
y: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const Render: React.FC<RenderProps> = React.memo(({ children, x, y }) => <div style={{
|
||||||
|
transform: `rotateX(${y}) rotateY(${x})`,
|
||||||
|
transition: `transform .1s`,
|
||||||
|
}}>
|
||||||
|
{children}
|
||||||
|
</div>)
|
||||||
|
|
||||||
|
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 <Render y={convertToDeg(y, 2)} x={convertToDeg(x, .75)}>
|
||||||
|
{children}
|
||||||
|
</Render>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Parallax
|
Loading…
x
Reference in New Issue
Block a user