-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcssani-examples.html
More file actions
555 lines (537 loc) · 23.1 KB
/
cssani-examples.html
File metadata and controls
555 lines (537 loc) · 23.1 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<!DOCTYPE html>
<html>
<head>
<meta name="author" content="Jiwon Shin">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<link rel="stylesheet" href="css/style.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.16/addons/p5.dom.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<title>CSS Animation: More Examples</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-110518171-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-110518171-1');
</script>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<main class="mdl-layout__content">
<div class="page-content">
<div class="full-page-content">
<h4><b>More Examples of css animation</b></h4>
<h5>Creating Shapes Using divs</h5>
<p>You can create shapes in html and css by creating empty div elements and assigning them widith height and background-color css properties.</p>
<style>
#squareDiv{
width: 100px;
height: 100px;
background-color: red;
}
</style>
<div id="squareDiv"></div>
<br>
<p><u>HTML</u>:</p>
<pre>
<div id="squareDiv"></div>
</pre>
<p><u>CSS</u>:</p>
<pre>
#squareDiv{
width: 100px;
height: 100px;
background-color: red;
}
</pre>
<p>We can also turn this square div in to a circle, or circle-like shape by giving it a css property called <b>border-radius</b>. border-radius takes in a numerical value as input and creates a circular edge around the four corners of the div element by using the numerical input as the radius of the circle.</p>
<p>For example, if we add</p>
<pre>
border-radius: 10px;
</pre>
<p>to the code we already have from above:</p>
<style>
#circleDiv1{
width: 100px;
height: 100px;
background-color: red;
border-radius: 20px;
}
</style>
<div id="circleDiv1"></div>
<br>
<p>We can also give the size of border-radius in percentages, relative to the size of the div element. So if I give 50% as my border-radius, this means that it will be 50% of my width and height of my div, which will end up being 50px and ultimately create a circle.</p>
<style>
#circleDiv2{
width: 100px;
height: 100px;
background-color: red;
border-radius: 50%;
}
</style>
<div id="circleDiv2"></div>
<br>
<p>If your width and height values are not the same, by setting border-radius to 50%, you will create an ellipse:</p>
<style>
#ellipseDiv{
width: 200px;
height: 100px;
background-color: red;
border-radius: 50%;
}
</style>
<div id="ellipseDiv"></div>
<p>You can also play around with the border elements of css to create outlines of shapes. In order to visualize the border around your div, you need to set your border-style. The default value of border-style is set to none, so you will need to over ride this by giving values such as solid, dotted, dashed and double. Use border-width to set the thickness of your border, and assign the color of your border with border-color.</p>
<pre>
#outlineDiv{
width: 100px;
height: 100px;
border-style: solid; /* other options: dashed, dotted, double... */
border-color: red;
border-width: 10px;
}
</pre>
<style>
#outlineDiv1{
width: 100px;
height: 100px;
border-style: solid;
border-color: red;
border-width: 10px;
position: relative;
display: inline-block;
}
</style>
<div id="outlineDiv1"></div>
<style>
#outlineDiv2{
width: 100px;
height: 100px;
border-style: dotted;
border-color: red;
border-width: 10px;
position: relative;
display: inline-block;
}
</style>
<div id="outlineDiv2"></div>
<style>
#outlineDiv3{
width: 100px;
height: 100px;
border-style: dashed;
border-color: red;
border-width: 10px;
position: relative;
display: inline-block;
}
</style>
<div id="outlineDiv3"></div>
<style>
#outlineDiv4{
width: 100px;
height: 100px;
border-style: double;
border-color: red;
border-width: 10px;
position: relative;
display: inline-block;
}
</style>
<div id="outlineDiv4"></div>
<p>You can also assign different styles, colors and widths for the top, bottom, left and right borders.</p>
<style>
#outlineDiv5{
width: 100px;
height: 100px;
border-top-style: dashed;
border-top-color: blue;
border-top-width: 10px;
border-bottom-style: dotted;
border-bottom-color: red;
border-bottom-width: 5px;
border-left-style: double;
border-left-color: green;
border-left-width: 20px;
border-right-style: solid;
border-right-color: yellow;
border-right-width: 30px;
}
</style>
<div id="outlineDiv5"></div>
<pre>
#outlineDiv{
width: 100px;
height: 100px;
border-top-style: dashed;
border-top-color: blue;
border-top-width: 10px;
border-bottom-style: dotted;
border-bottom-color: red;
border-bottom-width: 5px;
border-left-style: double;
border-left-color: green;
border-left-width: 20px;
border-right-style: solid;
border-right-color: yellow;
border-right-width: 30px;
}
</pre>
<p>You can actually create triangle shapes using borders as well: by assigning no width and height to the div and making all but one borders transparent.</p>
<style>
#outlineDiv6{
width: 0px;
height: 0px;
border-bottom: 100px solid red;
border-left: 100px solid transparent;
}
</style>
<div id="outlineDiv6"></div>
<pre>
#outlineDiv{
width: 0px;
height: 0px;
border-bottom: 100px solid red;
border-left: 100px solid transparent;
}
</pre>
<p>The most important part of this "css trick" is that you can "transparent" as your color value. Another thing to note is that you can merge border-bottom-width, border-bottom-style and border-bottom-color into a single line of css, by just referring to border-bottom, and separating the values for width, style and color with a space. </p>
<p>You can create different triangle shapes, depending on which borders you make transparent.</p>
<style>
#outlineDiv7{
width: 0px;
height: 0px;
border-bottom: 75px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
display: inline-block;
position: relative;
margin-right: 10px;
}
</style>
<div id="outlineDiv7"></div>
<style>
#outlineDiv8{
width: 0px;
height: 0px;
border-top: 75px solid blue;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
display: inline-block;
position: relative;
margin-right: 10px;
}
</style>
<div id="outlineDiv8"></div>
<style>
#outlineDiv9{
width: 0px;
height: 0px;
border-left: 75px solid green;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
display: inline-block;
position: relative;
margin-right: 10px;
}
</style>
<div id="outlineDiv9"></div>
<style>
#outlineDiv10{
width: 0px;
height: 0px;
border-right: 75px solid yellow;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
display: inline-block;
position: relative;
margin-right: 10px;
}
</style>
<div id="outlineDiv10"></div>
<p>Now that you know how to make shapes using html and css, you can apply movement to them. Please follow through <u><a class="p-link" href="cssani.html">this section of the tutorial</a></u> to learn how to animate using css.</p>
<h5>CSS Animation Example: From Workshop</h5>
<p>As requested, here is the code we wrote during the workshop on Tuesday. <u><a class="p-link" href="assets/css-animations.zip" download>Click to download as a compressed zip file</a></u>.</p>
<p><u>HTML</u>:</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="rectangle"></div>
<div class="circle"></div>
<div class="borders"></div>
<div class="triangle"></div>
</body>
</html>
</pre>
<p><u>CSS</u>:</p>
<pre>
.rectangle{
width: 100px;
height: 100px;
background-color: cornflowerblue;
animation-name: biggerToRed;
animation-duration: 2s;
animation-iteration-count: 1;
}
.circle{
width: 100px;
height: 100px;
background-color: cornflowerblue;
border-radius: 50%;
animation-name: biggerToRed;
animation-duration: 2s;
animation-iteration-count: 1;
animation-delay: 1s;
animation-fill-mode: forwards;
}
.borders{
width: 100px;
height: 100px;
border-style: solid;
border-width: 15px;
border-color: darkorange;
border-left-style: dotted;
border-left-color: darkblue;
border-left-width: 7px;
}
.triangle{
width: 0px;
height: 0px;
border-left-width: 50px;
border-left-style: solid;
border-left-color: red;
border-bottom-width: 50px;
border-bottom-style: solid;
border-top-width: 50px;
border-top-style: solid;
border-top-color: red;
border-right-width: 50px;
border-right-style: solid;
border-right-color: transparent;
border-bottom-color: transparent;
display: block;
position: relative;
animation-name: blink;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
@keyframes blueToRed{
from{
background-color: cornflowerblue;
}
to{
background-color: red;
}
}
@keyframes makeWider{
from{
width: 100px;
}
to{
width: 500px;
}
}
@keyframes biggerToRed{
from{
background-color: cornflowerblue;
width: 100px;
height: 100px;
}
to{
background-color: red;
width: 500px;
height: 200px;
}
}
@keyframes moveDiv{
0%{
left: 0px;
/* border-left-color: red;
border-top-color: red;*/
transform: rotateY(0deg);
opacity: 0.5;
}
50%{
left: 400px;
/* border-left-color: blue;
border-top-color: blue;*/
transform: rotateY(120deg);
opacity: 1.0;
}
75%{
/* border-left-color: yellow;
border-top-color: yellow;*/
transform: rotateY(270deg);
}
100%{
left: 200px;
/* border-left-color: green;
border-top-color: green;*/
transform: rotateY(90deg);
opacity: 0.4;
}
}
@keyframes blink{
from{
opacity: 0.6;
filter: brightness(80%);
}
to{
opacity: 1.0;
filter: brightness(120%);
}
}
</pre>
<h5>Parallax Background</h5>
<iframe height="500px" src="parallax-demo.html"></iframe>
<br>
<p><u><a class="p-link" href="parallax-demo.html">Click to view the demo as a full web page.</a></u></p>
<p>Let's start off with creating three divs, one for each background. We will also give class names for each of these sections.</p>
<pre>
<div class="section-1"></div>
<div class="section-2"></div>
<div class="section-3"></div>
</pre>
<p>Now, we will give it background images to each of these sections in css.</p>
<pre>
.section-1{
background-image: url(img/parallax/bg1.jpg);
}
.section-2{
background-image: url(img/parallax/bg2.jpg);
}
.section-3{
background-image: url(img/parallax/bg3.jpg);
}
</pre>
<p>As of now, nothing will appear on your screen, because you haven't given your html, body and div elements any height yet. If a specific height is not set with css, as all of our html content has height of 0 (div has a height of 0px if there is no content inside of the div - remember that a div element is used just to group html elements and doesn't have any visual qualities) and so the web page does not display anything. So we will set the height of our html, body and the 3 sections of div elements to 100%.</p>
<pre>
html, body{
height: 100%;
}
.section-1, .section-2, .section-3{
height: 100%;
}
</pre>
<p>One important thing to note in the css above is that, you can give multiple html / class / id elements the same style by linking them with a comma. For example, as I want all of my three sections to share a css property of height 100%, I can do this in one chunck of css by referring to all three classes at the same time by doing: .section-1, .section-2, .section-3</p>
<p>Now, you will notice, depending on the size of your images, the background images that you gave will be either stretched out or tiled to fit the space of your browser. Let's set our background images to be at the center, to not repeat (to prevent the tiling of the image) and to cover the size of the browser.</p>
<pre>
.section-1, .section-2, .section-3{
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</pre>
<p>With this, we have set the size and position of our background so that it auto-adjusts to the size of the browser. However, for now, it looks like as if the images are just placed in order and it doesn't have the parallax effect yet. Now for the one magic line that will create this parallax effect: <b>background-attachment: fixed;</b></p>
<pre>
.section-1, .section-2, .section-3{
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</pre>
<p>That additional line of css will fix the position of the background image regardless of the scrolling. As it scrolls, it reveals the background of the next div, from bottom to top.
<br>
Now we have a basic parallax web page. You can of course, put in div elements with text in between the div elements with the background images. You can also put in content inside of the div elements with background images, to place them along with each of the background image of the section div. Here is the complete html and css code of the demo web page:</p>
<p><u>HTML</u>:</p>
<pre>
<div class="section-1">
<div class="caption">
<span class="caption-text">Title of Website</span>
</div>
</div>
<div class="section-text">
<div class="inner-text">
<p>This is a place where you can enter in text content.</p>
</div>
</div>
<div class="section-2"></div>
<div class="section-text">
<div class="inner-text">
<p>This is another place where you can enter in text content.</p>
</div>
</div>
<div class="section-3"></div>
</pre>
<p><u>CSS</u>:</p>
<pre>
html, body{
height: 100%;
margin: 0;
font-family: "Helvetica Neue", sans-serif;
}
.section-1, .section-2, .section-3{
position: relative;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
}
.section-1{
background-image: url(img/parallax/bg1.jpg);
}
.section-2{
background-image: url(img/parallax/bg2.jpg);
}
.section-3{
background-image: url(img/parallax/bg3.jpg);
}
.section-text{
position: relative;
}
.caption{
position: absolute;
top: 50%;
left: 0px;
width: 100%;
text-align: center;
}
.caption-text{
background-color: white;
color: #cecece;
font-size: 42px;
font-weight: bold;
padding: 15px
}
.inner-text{
padding: 50px 80px;
background-color: black;
color: white;
font-size: 20px;
}
</pre>
</div>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<ul class="mdl-mini-footer__link-list">
<li><u><a class="p-link" href="index.html" target="_self">BACK TO MAIN</a></u></li>
</ul>
</div>
<div class="mdl-mini-footer__right-section">
<ul class="mdl-mini-footer__link-list">
<li>Workshops By <u><a class="p-link" href="http://jiwonshin.com" target="_blank">Jiwon Shin</a></u></li>
</ul>
</div>
</footer>
</div>
</main>
</div>
</body>
<script src="js/background.js"></script>
</html>