File tree Expand file tree Collapse file tree 4 files changed +64
-38
lines changed
Expand file tree Collapse file tree 4 files changed +64
-38
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Image from 'next/image';
44import { useEffect , useRef , useState } from 'react' ;
55
66import Pill from '@/components/shared/pill' ;
7- import '@/styles/sql-editor- hero.css ' ;
7+ import { generateScrollAnimationCSS } from '@/utils/ hero-animate ' ;
88
99type HeroProps = {
1010 // subjects is an array of comparison subjects.
@@ -51,7 +51,15 @@ const Hero = ({ subjects }: HeroProps) => {
5151 { initialed && isSubjectsScrollable ? (
5252 < >
5353 < div className = "absolute z-[1] h-4 w-full bg-white blur-md" />
54- < div className = "scroll-animation flex flex-col items-end justify-center" >
54+ < style
55+ // eslint-disable-next-line react/no-danger
56+ dangerouslySetInnerHTML = { {
57+ __html : generateScrollAnimationCSS ( scrollableSubjects . length ) ,
58+ } }
59+ />
60+ < div
61+ className = { `scroll-animation-${ scrollableSubjects . length } flex flex-col items-end justify-center` }
62+ >
5563 { scrollableSubjects . map ( ( subject , index ) => (
5664 // eslint-disable-next-line react/no-array-index-key
5765 < mark key = { `${ subject } -${ index } ` } className = "bg-transparent text-primary-1" >
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Image from 'next/image';
44import { useEffect , useRef , useState } from 'react' ;
55
66import Pill from '@/components/shared/pill' ;
7- import '@/styles/sql-editor- hero.css ' ;
7+ import { generateScrollAnimationCSS } from '@/utils/ hero-animate ' ;
88
99type HeroProps = {
1010 // subjects is an array of comparison subjects.
@@ -51,7 +51,15 @@ const Hero = ({ subjects }: HeroProps) => {
5151 { initialed && isSubjectsScrollable ? (
5252 < >
5353 < div className = "absolute z-[1] h-4 w-full bg-white blur-md" />
54- < div className = "scroll-animation flex flex-col items-end justify-center" >
54+ < style
55+ // eslint-disable-next-line react/no-danger
56+ dangerouslySetInnerHTML = { {
57+ __html : generateScrollAnimationCSS ( scrollableSubjects . length ) ,
58+ } }
59+ />
60+ < div
61+ className = { `scroll-animation-${ scrollableSubjects . length } flex flex-col items-end justify-center` }
62+ >
5563 { scrollableSubjects . map ( ( subject , index ) => (
5664 // eslint-disable-next-line react/no-array-index-key
5765 < mark key = { `${ subject } -${ index } ` } className = "bg-transparent text-primary-1" >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /**
2+ * Generates a CSS string for a scroll animation with a specified number of steps.
3+ *
4+ * @param size - The number of steps in the scroll animation.
5+ * @returns A string containing the CSS for the scroll animation.
6+ *
7+ * The generated CSS includes:
8+ * - Keyframes for the scroll animation, where each step translates the element vertically.
9+ * - A CSS class that applies the animation with a duration based on the number of steps.
10+ */
11+ export const generateScrollAnimationCSS = ( size : number ) : string => {
12+ const keyframes : string [ ] = [ ] ;
13+ const stepPercentage = 100 / ( size - 1 ) ;
14+ const transformStep = 100 / size ;
15+ const animateDuration = 3 ;
16+
17+ for ( let i = 0 ; i < size ; i ++ ) {
18+ const percentage = i * stepPercentage ;
19+ const transformValue = - i * transformStep ;
20+
21+ keyframes . push ( `
22+ ${ ( i - 0.5 ) * stepPercentage } % {
23+ transform: translateY(${ transformValue } %);
24+ }
25+ ${ percentage } % {
26+ transform: translateY(${ transformValue } %);
27+ }
28+ ` ) ;
29+ }
30+
31+ const keyframesCSS = `
32+ @keyframes hero-scroll-${ size } {
33+ ${ keyframes . join ( '' ) }
34+ }
35+ ` ;
36+
37+ return `
38+ .scroll-animation-${ size } {
39+ animation: hero-scroll-${ size } ${ animateDuration * ( size - 1 ) } s ease-in-out infinite;
40+ animation-delay: ${ animateDuration } s;
41+ }
42+ ${ keyframesCSS }
43+ ` ;
44+ } ;
You can’t perform that action at this time.
0 commit comments