-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter20.html
More file actions
293 lines (268 loc) Β· 8.93 KB
/
chapter20.html
File metadata and controls
293 lines (268 loc) Β· 8.93 KB
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
287
288
289
290
291
292
293
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 20: CSS Transitions and Animations</title>
<link rel="stylesheet" href="style.css">
<style>
/* Animation styles */
.box {
width: 60px;
height: 60px;
background: crimson;
border-radius: 8px;
margin-bottom: 10px;
}
/* Basic Transition */
.transition-basic {
transition: all 1.5s;
}
.transition-basic:hover {
width: 150px;
height: 150px;
background: purple;
transform: rotate(45deg);
}
/* Delay */
.transition-delay {
transition: transform 2s ease;
transition-delay: 1s;
}
.transition-delay:hover {
transform: translateX(200px);
}
/* Timing functions demo */
.timing-track {
width: 320px;
height: 70px;
background: #ddd;
position: relative;
border-radius: 5px;
overflow: hidden;
margin-bottom: 15px;
}
.timing-ball {
width: 40px;
height: 40px;
border-radius: 50%;
background: teal;
position: absolute;
top: 15px;
left: 0;
transition: left 2s;
}
/* Individual timing function tracks */
.timing-track.ease:hover .timing-ball {
transition-timing-function: ease;
left: 280px;
}
.timing-track.linear:hover .timing-ball {
transition-timing-function: linear;
left: 280px;
}
.timing-track.ease-in:hover .timing-ball {
transition-timing-function: ease-in;
left: 280px;
}
.timing-track.ease-out:hover .timing-ball {
transition-timing-function: ease-out;
left: 280px;
}
.timing-track.ease-in-out:hover .timing-ball {
transition-timing-function: ease-in-out;
left: 280px;
}
/* Two-step animation */
@keyframes two-step {
0% { transform: translateX(0); background: red; }
100% { transform: translateX(150px); background: yellow; }
}
.animation-basic {
width: 80px;
height: 80px;
background: red;
animation: two-step 2s infinite alternate;
border-radius: 10px;
}
/* Multi-keyframes */
@keyframes multi-keyframes {
0% { left: 0; background: red; }
25% { left: 50px; background: orange; }
50% { left: 100px; background: blue; }
75% { left: 150px; background: violet; }
100% { left: 200px; background: green; }
}
.animation-multi {
position: relative;
width: 80px;
height: 80px;
background: red;
animation: multi-keyframes 4s infinite alternate;
border-radius: 10px;
}
/* Animation with delay & iteration */
@keyframes delay-iteration {
0% { transform: translateX(0); background: pink; }
50% { transform: translateX(150px); background: purple; }
100% { transform: translateX(0); background: pink; }
}
.animation-delay {
width: 80px;
height: 80px;
background: pink;
border-radius: 10px;
animation: delay-iteration 2s ease-in-out 1s infinite;
}
/* Animation directions */
@keyframes move-left-right {
from { transform: translateX(0); }
to { transform: translateX(200px); }
}
.animation-direction-reverse {
width: 80px;
height: 80px;
background: lightgreen;
animation: move-left-right 3s linear infinite reverse;
border-radius: 10px;
}
.animation-direction-alternate {
width: 80px;
height: 80px;
background: orange;
animation: move-left-right 3s linear infinite alternate;
border-radius: 10px;
}
/* Timing function in animation */
.animation-timing {
width: 80px;
height: 80px;
background: violet;
border-radius: 10px;
animation: move-left-right 3s ease-in-out infinite alternate;
}
/* Shorthand */
.animation-shorthand {
width: 80px;
height: 80px;
background: cyan;
border-radius: 10px;
animation: multi-keyframes 4s linear infinite alternate;
}
</style>
</head>
<body>
<h2 class="chapter-header">Chapter 20: CSS Transitions and Animations</h2>
<!-- Basic Transition -->
<div class="tag-section">
<h3>Basic Transition</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Hover to see size, color, and rotation change smoothly:</p>
<div class="box transition-basic"></div>
</div>
</div>
</div>
<!-- Transition with Delay -->
<div class="tag-section">
<h3>Transition with Delay</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Hover to move right, but it starts after 1 second delay:</p>
<div class="box transition-delay"></div>
</div>
</div>
</div>
<!-- Timing Functions -->
<div class="tag-section">
<h3>Transition Timing Functions</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Hover each track to see the different timing functions in action:</p>
<p><b>Ease:</b> (default - slow start, fast, slow end)</p>
<div class="timing-track ease">
<div class="timing-ball"></div>
</div>
<p><b>Linear:</b> (same speed from start to end)</p>
<div class="timing-track linear">
<div class="timing-ball"></div>
</div>
<p><b>Ease-in:</b> (slow start, fast end)</p>
<div class="timing-track ease-in">
<div class="timing-ball"></div>
</div>
<p><b>Ease-out:</b> (fast start, slow end)</p>
<div class="timing-track ease-out">
<div class="timing-ball"></div>
</div>
<p><b>Ease-in-out:</b> (slow start and end)</p>
<div class="timing-track ease-in-out">
<div class="timing-ball"></div>
</div>
</div>
</div>
</div>
<!-- Two-step Animation -->
<div class="tag-section">
<h3>Two-step Animation</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Box moves right and changes color continuously:</p>
<div class="animation-basic"></div>
</div>
</div>
</div>
<!-- Multiple Keyframes -->
<div class="tag-section">
<h3>Multiple Keyframes Animation</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Box changes position and color at multiple steps:</p>
<div class="animation-multi"></div>
</div>
</div>
</div>
<!-- Delay & Iteration -->
<div class="tag-section">
<h3>Animation with Delay & Iteration</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Starts after 1s, runs continuously:</p>
<div class="animation-delay"></div>
</div>
</div>
</div>
<!-- Direction -->
<div class="tag-section">
<h3>Animation Direction</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Reverse direction (runs backwards):</p>
<div class="animation-direction-reverse"></div>
<p>Alternate back and forth:</p>
<div class="animation-direction-alternate"></div>
</div>
</div>
</div>
<!-- Animation Timing -->
<div class="tag-section">
<h3>Animation Timing Function</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Ease-in-out movement during animation:</p>
<div class="animation-timing"></div>
</div>
</div>
</div>
<!-- Shorthand -->
<div class="tag-section">
<h3>Shorthand Animation Property</h3>
<div class="tag-demo">
<div class="head-demo">
<p>Using shorthand syntax:</p>
<div class="animation-shorthand"></div>
</div>
</div>
</div>
</body>
</html>