Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sponsor carousel #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Links from '../Header/Links'
import ProjectList from '../ProjectList/ProjectList'
import { PROJECTS, PROJECTS_SHOWN_ON_HOMEPAGE } from '../constants'
import { StyledLink } from '../components/StyledLink'
import SponsorCarousel from '../components/SponsorCarousel'

const StyledMain = styled.div`
position: relative;
Expand Down Expand Up @@ -58,6 +59,13 @@ const Home = () => {
</p>
</Paragraph>
<Spacer size={64} />

<Paragraph title="CompSoc sponsors">
<SponsorCarousel />
</Paragraph>

<Spacer size={64} />

<Paragraph title="Who can join?">
<p>
Anyone! The only condition? Be prepared to share your journey.
Expand Down
106 changes: 106 additions & 0 deletions src/components/SponsorCarousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { useEffect, useRef } from 'react'
import { motion, useAnimation } from 'framer-motion'

const images = [
'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Meta_Platforms_Inc._logo.svg/2560px-Meta_Platforms_Inc._logo.svg.png',
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/2560px-Google_2015_logo.svg.png',
'https://via.placeholder.com/250',
'https://via.placeholder.com/350',
'https://via.placeholder.com/450',
]

const duplicatedImages = [...images, ...images]

const SponsorCarousel = () => {
const controls = useAnimation()
const containerRef = useRef(null)

useEffect(() => {
let isMounted = true

const animateTicker = async () => {
if (isMounted) {
await controls.start({ x: '-50%' })
controls.set({ x: '0%' })
animateTicker()
}
}

if (containerRef.current) {
animateTicker()
}

return () => {
isMounted = false
}
}, [controls])

const duration = images.length * 5

return (
<div style={{ position: 'relative', overflow: 'hidden', height: '100px' }}>
<div
style={{
position: 'absolute',
zIndex: 10,
right: 0,
top: 0,
bottom: 0,
width: '50%',
background:
'linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0) 25%)',
}}
/>
<div
style={{
position: 'absolute',
zIndex: 10,

left: 0,
top: 0,
bottom: 0,
width: '50%',
background:
'linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0) 25%)',
}}
/>
<motion.div
ref={containerRef}
initial={{ x: '0%' }}
animate={controls}
transition={{
type: 'tween',
ease: 'linear',
duration: duration,
}}
style={{
display: 'flex',
gap: '5rem',
width: `500%`,
height: '100px',
position: 'absolute',
}}>
{duplicatedImages.map((image, index) => (
<div
key={index}
style={{
width: `${50 / duplicatedImages.length}%`,
backgroundImage: `url(${image})`,
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
borderLeft:
index === 0 ? 'none' : '1px solid rgba(255, 255, 255, 0.2)',
borderRight:
index === duplicatedImages.length - 1
? 'none'
: '1px solid rgba(255, 255, 255, 0.2)',
}}
/>
))}
</motion.div>
</div>
)
}

export default SponsorCarousel