-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.idyll
286 lines (228 loc) · 8.11 KB
/
index.idyll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
[meta title:"Stack Scroll" description:"Tutorial on Stacked Scrolling" /]
[Header
title:"Stacking Scroller Components"
subtitle:"Introduction to leveraging multiple Scrollers in Idyll"
author:"Megan Vo"
authorLink:"https://github.com/megan-vo"/]
[div className:"line"][/div]
[br/]
[div className:"text"]
[p][a href:"https://idyll-lang.org/" target:"_blank"]Idyll's[/a] Scroller component is a useful way to incorporate
more narrative structure into an article. As its name suggests, it provides a scroll-based presentation layout
that can manipulate graphics upon each "step" that is entered.[/p]
This tutorial will focus on introducing [span className:"emphasize"]multiple Scroller components[/span] in one Idyll
document to further aid your scrollytelling needs. If you are not familiar with Idyll's Scrollers, take a peek at this
[a href:"https://idyll-lang.org/gallery/scaffolding-interactives" target:"_blank"]tutorial[/a] first. Otherwise, let's get
started!
[br/]
### What are Stacked Scrollers?
Instead of one Scroller component per document, stacking Scrollers simply translates to
declaring multiple Scroller components one after another. This way, each Scroller can be thought of as its own
section with steps that only it can control.
[br/]
### Why Stack?
Stacking allows us to easily transition between the different graphics of each component. Take for example,
the smooth transitions between the graphics of the article below.
[figure]
[img src:"static/images/fugazi.gif" className:"gif" /]
[figcaption]
[a href:"https://idyll-lang.org/gallery/the-d-i-y-data-of-fugazi" target:"_blank"]The D-I-Y Data of Fugazi[/a]
by Matthew Conlen.
[/figcaption]
[/figure]
[p]With stacking, the graphic of each Scroller slides up and replaces the previous
one on the screen -- and quite easily too. Since each Scroller component only allows
for one graphic, switching between them is a bit more difficult and
clunky when using just one Scroller.[/p]
Perhaps one of the biggest perks is that stacking lets us include multiple animated graphics per document because each Scroller
controls their *own* set of steps. This also gives us greater customizeability
in terms of style and functionality since every Scroller has a corresponding [span className:"emphasize"]id[/span].
[br/]
### Let's Build Something
To get acquainted with stacked scrolling, below is a short example of customizing each
of the stacked Scroller components.
For this example, we've made changes to the [span className:"emphasize"]styles.css[/span] and [span className:"emphasize"]index.idyll[/span] files.
Also in the [span className:"emphasize"]package.json[/span] file, we have switched to the ```layout: centered``` format.
[img src:"static/images/arrow.svg" className:"arrow"/]
[/div]
// Scroller Tutorial
[var name:"barStep" value:0 /]
[Scroller currentStep:barStep]
[Graphic]
// Tie barStep to img class
[img src:"static/images/bar.svg"
className:`barStep === 0 ? "bar" : "bar rotate" + barStep `/]
[/Graphic]
[Step]
[p]The **bar** on the right belongs to this first Scroller component.[/p]
Let's first look at how we can animate **within** a Scroller. Watch how it rotates
as you move to the next step.
[/Step]
[Step]
[p]We've reached the next step! You can animate a graphic within a particular Scroller based on what step is entered.[/p]
To keep track of the current step you are in, you can assign a variable to the Scroller's
```currentStep``` prop and tie it to your graphic:
```
[var name:"barStep" value:0 /]
[Scroller currentStep:barStep]
[Graphic]
[img src:"static/images/bar.svg"
className:`barStep === 0 ? "bar" :
"bar rotate" + barStep `/]
[/Graphic]
[Step]
...
[/Step]
[/Scroller]
```
[/Step]
[Step]
Now we can write some basic transformations in the [span className:"emphasize"]style.css[/span] file to reflect the
```barStep``` prop updates:
```css
.bar {
margin-left: 42vw;
background: transparent;
width: 25vw;
height: 10vh;
transition: 400ms linear all;
}
.rotate1 {
transform: rotate(90deg);
}
.rotate2 {
transform: rotate(210deg);
}
```
[/Step]
[Step]
[p]But let's say you want to include another graphic. We could stay here on this Scroller but it would
get a little messy... [/p]
So let's **stack**!
[/Step]
[/Scroller]
// SECOND SCROLLER
[var name:"circleStep" value:0/]
[Scroller currentStep:circleStep]
[Graphic]
[img src:"static/images/circle.svg"
className:`circleStep === 0 ? "circle" : "circle enlarge" + circleStep `/]
[/Graphic]
[Step]
[p]Welcome to the second Scroller! Like the first Scroller, we have kept
track of the step we're on by passing a different variable to the ```currentStep``` prop: [/p]
```
// Second Scroller
[var name:"circleStep" value:0/]
[Scroller currentStep:circleStep]
...
[/Scroller]
```
Now watch for a different animation as you enter
the next step.
[/Step]
[Step]
[p]
As mentioned previously, each Scroller has a unique [span className:"emphasize"]id[/span].[/p] The id format is ```#idyll-scroll-[num] ``` starting at 0.
Since this is the second Scroller, its id is ```#idyll-scroll-1 ```.
[/Step]
[Step]
[p]This comes in handy when you want to change the style for a particular Scroller only.[/p]
Here, we've changed this graphic's background color in the [span className:"emphasize"]style.css[/span]
file:
```css
#idyll-scroll-1 .idyll-scroll-graphic {
background: #5BAFC1;
}
```
[/Step]
[Step]
[p]And that's pretty much it![/p] Go ahead and scroll down for the summary code snippets.
[/Step]
[/Scroller]
[br/]
// Code snippet portion
[div className:"code"]
### Snippets
If you want to use the code snippets directly, you can use the default [a href:"https://github.com/megan-vo/stacked-scrolling-tutorial/tree/master/static/images" target:"_blank"]bar and circle images[/a] as well.
```
// First Scroller
[var name:"barStep" value:0 /]
[Scroller currentStep:barStep]
[Graphic]
[img src:"static/images/bar.svg"
className:`barStep === 0 ? "bar" :
"bar rotate" + barStep `/]
[/Graphic]
[Step]
... // Step content here
[/Step]
[Step]
...
[/Step]
[/Scroller]
// Second Scroller
[var name:"circleStep" value:0 /]
[Scroller currentStep:circleStep]
[Graphic]
[img src:"static/images/circle.svg"
className:`circleStep === 0 ? "circle" :
"circle enlarge" + circleStep `/]
[/Graphic]
[Step]
...
[/Step]
[Step]
..
[/Step]
[/Scroller]
```
```css
/* CSS for scroller portion */
.bar, .circle {
margin-left: 42vw;
background: transparent;
transition: 400ms linear all;
}
/* Format the graphics */
.circle {
height: 35vh;
}
.bar {
width: 25vw;
height: 10vh;
}
/* Animations */
.rotate1 {
transform: rotate(90deg);
}
.rotate2 {
transform: rotate(210deg);
}
.enlarge1 {
transform: scale(2);
}
.enlarge2 {
transform: scale(2.2);
}
/* Change graphic background based on Scroller id */
#idyll-scroll-0 .idyll-scroll-graphic {
background: #F0F0F0;
}
#idyll-scroll-1 .idyll-scroll-graphic {
background: #5BAFC1;
}
```
[/div]
[br/]
### Final Notes
// Link to docs
[p]Interested in exploring more? [span className:"emphasize"]Idyll's Docs[/span] has information on all the
[a href:"https://idyll-lang.org/docs/components" target:"_blank"]built-in components[/a]
including the Scroller. If you're looking to get started somewhere,
[a href:"https://idyll-lang.org/docs/getting-started" target:"_blank"]this page[/a] in the Docs will
help you get set up.[/p]
// Custom components
Note that you can apply the same Scroller concepts from the CSS example above to control custom JavaScript
components as well in Idyll. Check out the [a href:"https://idyll-lang.org/docs/components/custom" target:"_blank"]custom
components[/a] page on how to incorporate those into your Idyll document.