Skip to content

Commit b201515

Browse files
author
Adam Plesnik
committed
Add intro to the docs
1 parent a61abb9 commit b201515

File tree

6 files changed

+93
-6
lines changed

6 files changed

+93
-6
lines changed

src/css/keyframes.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@
6262
transform: translateY(-60%);
6363
}
6464
}
65+
66+
@keyframes opacity {
67+
from {
68+
opacity: 0;
69+
}
70+
to {
71+
opacity: 1;
72+
}
73+
}

src/demos/DemoWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ const DemoWrapper = ({
2626
addWithSpace(className)
2727
}
2828
>
29-
{children}
3029
{actionButton && (
31-
<div className="absolute right-3 top-3">
30+
<div className="sticky top-0 z-10 -mb-10 flex justify-end pr-2 pt-2">
3231
<ActionButton
3332
Icon={Repeat}
3433
IconOnClick={StepForward}
@@ -37,6 +36,7 @@ const DemoWrapper = ({
3736
/>
3837
</div>
3938
)}
39+
{children}
4040
</div>
4141
)
4242
}

src/demos/TimelineOverrideDemo.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Code from '../components/Code'
2+
import DemoWrapper from './DemoWrapper'
3+
4+
const TimelineOverrideDemo = () => {
5+
return (
6+
<DemoWrapper className="max-h-60 sm:max-h-48" actionButton>
7+
<div className="sticky top-0 flex flex-col gap-4 p-8">
8+
<div className="flex flex-1 items-center">
9+
<span className="animate-opacity rounded-lg bg-sky-500/40 p-4 dark:bg-fuchsia-300/60">
10+
<Code>timeline</Code> <span className="text-sm font-medium">before</span>{' '}
11+
<Code>animate-opacity</Code>
12+
</span>
13+
</div>
14+
<div className="flex flex-1 items-center">
15+
<span className="animate-opacity rounded-lg bg-sky-500/40 p-4 timeline dark:bg-fuchsia-300/60">
16+
<Code>animate-opacity</Code> <span className="text-sm font-medium">before</span>{' '}
17+
<Code>timeline</Code>
18+
</span>
19+
</div>
20+
</div>
21+
<div className="h-96"></div>
22+
</DemoWrapper>
23+
)
24+
}
25+
26+
export default TimelineOverrideDemo

src/docs/Docs.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import Heading from '../components/Heading'
44
import Paragraph from '../components/Paragraph'
55
import MultiRangeDemo from '../demos/MultiRangeDemo'
66
import SupportsDemo from '../demos/SupportsDemo'
7-
import { multiRange, multiRangeKeyframes, supports } from '../utils/demoExamples'
7+
import TimelineOverrideDemo from '../demos/TimelineOverrideDemo'
8+
import {
9+
keyframes101,
10+
keyframes102,
11+
keyframes103,
12+
multiRange,
13+
multiRangeKeyframes,
14+
supports,
15+
} from '../utils/demoExamples'
816
import DocsTable from './DocsTable'
917

1018
const animationTimelineClasses = [
@@ -51,6 +59,25 @@ const Docs = () => {
5159
<Heading size={2} id="documentation">
5260
Documentation
5361
</Heading>
62+
<Heading size={3} id="documentation-101">
63+
How to Make Your CSS Animation Scroll-driven
64+
</Heading>
65+
<Paragraph>
66+
CSS animations consist of two components, a set of keyframes and a style describing the
67+
animation. Let's declare a simple <Code>@opacity</Code> keyframe set and apply it to an
68+
element we want to control by a scroll timeline.
69+
</Paragraph>
70+
<CodeBlock language="css">{keyframes101}</CodeBlock>
71+
<CodeBlock language="html">{keyframes102}</CodeBlock>
72+
<Paragraph>
73+
To effectively control the animation, make sure to declare the timeline in the code after
74+
the animation. By default, the shorthand <Code>animation</Code> property sets the{' '}
75+
<Code>animation-timeline: auto</Code> unless set otherwise. However, using this plugin and
76+
Tailwind CSS animations ensures that the declaration order is correct.
77+
</Paragraph>
78+
<CodeBlock language="css">{keyframes103}</CodeBlock>
79+
<Paragraph>Scroll the container.</Paragraph>
80+
<TimelineOverrideDemo />
5481
<Heading size={3} href="#timeline" hrefType="demo" id="documentation-animation-timeline">
5582
Animation Timeline
5683
</Heading>
@@ -59,7 +86,6 @@ const Docs = () => {
5986
animation.
6087
</Paragraph>
6188
<DocsTable items={animationTimelineClasses} />
62-
6389
<Heading size={3} href="#range" hrefType="demo" id="documentation-scroll-timeline">
6490
Scroll Timeline
6591
</Heading>
@@ -68,7 +94,6 @@ const Docs = () => {
6894
element.
6995
</Paragraph>
7096
<DocsTable items={scrollTimelineClasses} />
71-
7297
<Heading size={3} href="#range" hrefType="demo" id="documentation-view-timeline">
7398
View Timeline
7499
</Heading>
@@ -85,7 +110,7 @@ const Docs = () => {
85110
on the animated element.
86111
</Paragraph>
87112
<DocsTable items={rangeClasses} />
88-
<Paragraph size="small" className="pt-6">
113+
<Paragraph className="pt-6">
89114
Scroll the container to see each how range utility class affects the animation.
90115
</Paragraph>
91116
<MultiRangeDemo />

src/utils/demoExamples.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,29 @@ export const supports = `<div>
8282
</div>
8383
...
8484
</div>`
85+
86+
export const keyframes101 = `@keyframes opacity {
87+
from {
88+
opacity: 0;
89+
}
90+
to {
91+
opacity: 1;
92+
}
93+
}`
94+
95+
export const keyframes102 = `<div class="animate-opacity timeline">
96+
<!-- The animation should be controlled by the timeline. -->
97+
</div>`
98+
99+
export const keyframes103 = `
100+
.timeline { /* This timeline would be overriden */
101+
animation-timeline: scroll(y);
102+
}
103+
104+
.animate-opacity {
105+
animation: opacity 8s ease-in-out both;
106+
}
107+
108+
.timeline { /* This is the correct order */
109+
animation-timeline: scroll(y);
110+
}`

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
/* Scroll-driven animations */
1717
appear: 'appear auto cubic-bezier(0.65, 0.05, 0.17, 0.99) forwards',
1818
down: 'translate-down auto ease-in-out forwards',
19+
opacity: 'opacity 8s ease-in-out forwards',
1920
'scale-to-right': 'scale-to-right auto linear forwards',
2021
'translate-down': 'translate-down auto cubic-bezier(0.65, 0.05, 0.17, 0.99) forwards',
2122
'translate-up': 'translate-up auto ease-in-out forwards',

0 commit comments

Comments
 (0)