generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SayarB/anirudh-dev
feat: meet the team horizontal scroll
- Loading branch information
Showing
11 changed files
with
4,120 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { motion } from 'framer-motion'; | ||
|
||
const TallOuterContainer = styled.div.attrs(({ dynamicHeight }) => ({ | ||
style: { height: `${dynamicHeight}px` }, | ||
}))` | ||
position: relative; | ||
width: 100%; | ||
`; | ||
|
||
const StickyInnerContainer = styled.div` | ||
position: sticky; | ||
top: 0; | ||
height: 100vh; | ||
width: 100%; | ||
overflow-x: hidden; | ||
`; | ||
|
||
const HorizontalTranslateContainer = styled.div.attrs(({ translateX }) => ({ | ||
style: { transform: `translate(${translateX}px, -50%)` }, | ||
}))` | ||
position: absolute; | ||
will-change: transform; | ||
top: 50%; | ||
`; | ||
|
||
const calcDynamicHeight = (objectWidth) => { | ||
const vw = window.innerWidth; | ||
const vh = window.innerHeight; | ||
return objectWidth - vw + vh -160; | ||
}; | ||
|
||
const handleDynamicHeight = (ref, setDynamicHeight) => { | ||
const objectWidth = ref.current.scrollWidth; | ||
const dynamicHeight = calcDynamicHeight(objectWidth); | ||
setDynamicHeight(dynamicHeight*4/3); | ||
}; | ||
|
||
const applyScrollListener = (ref, setTranslateX) => { | ||
const elem = document.getElementById('main-thing'); | ||
elem?.addEventListener('scroll', () => { | ||
// console.log(ref); | ||
const offsetTop = -ref.current?.offsetTop; | ||
setTranslateX(offsetTop*3/4); | ||
// console.log(offsetTop); | ||
}); | ||
}; | ||
|
||
const HorizontalScroll = ({ title, children }) => { | ||
const [dynamicHeight, setDynamicHeight] = useState(null); | ||
const [translateX, setTranslateX] = useState(0); | ||
|
||
const containerRef = useRef(null); | ||
const objectRef = useRef(null); | ||
|
||
const resizeHandler = () => { | ||
handleDynamicHeight(objectRef, setDynamicHeight); | ||
}; | ||
|
||
useEffect(() => { | ||
handleDynamicHeight(objectRef, setDynamicHeight); | ||
window.addEventListener('resize', resizeHandler); | ||
applyScrollListener(containerRef, setTranslateX); | ||
}, []); | ||
|
||
return ( | ||
<TallOuterContainer dynamicHeight={dynamicHeight}> | ||
<StickyInnerContainer ref={containerRef}> | ||
<div className=" top-0 left-0 w-full pt-[15vh] text-dark"> | ||
<motion.div | ||
initial={{ scale: 1.5 }} | ||
whileInView={{ scale: 1 }} | ||
viewport={{ once: false, amount: 1 }} | ||
transition={{ duration: 1 }} | ||
className="w-[100vw] lg:w-[30vw] lg:min-w-[600px] mx-auto" | ||
> | ||
<h1 className="uppercase font-sans text-[3rem] font-extrabold text-center tracking-wider"> | ||
{title} | ||
</h1> | ||
</motion.div> | ||
</div> | ||
<HorizontalTranslateContainer translateX={translateX} ref={objectRef}> | ||
{children} | ||
</HorizontalTranslateContainer> | ||
</StickyInnerContainer> | ||
</TallOuterContainer> | ||
); | ||
}; | ||
|
||
export default HorizontalScroll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, {FC} from 'react' | ||
import levelsNoise from '../assets/levelsNoise.svg' | ||
import Image from 'next/image' | ||
|
||
interface Props { | ||
level: "01" | "02" | "03" | "04" | ||
} | ||
|
||
const Level: FC<Props> = ({ level }) => { | ||
return ( | ||
<div className='relative'> | ||
<Image className='w-full h-full' src={levelsNoise} alt='' /> | ||
<h1 className='uppercase absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-stone-500 font-extrabold text-center xl:text-7xl lg:text-6xl text-5xl'>Level {level}</h1> | ||
</div> | ||
) | ||
} | ||
|
||
export default Level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.