Practical lesson
To create several animations at once, each moving object lives in its own “layer”: in Flash this was a separate Layer, in HTML it is a separate element inside the stage. The work starts with planning: in a storyboard (a frame-by-frame plan) the objects, their start and end states and durations are written down. Then the stage (width, height, background) is created, and an element and its CSS animation are written for each object. Every animation can have its own duration and speed, so the objects move independently of each other (the cloud in 10 seconds, the sun in 6 seconds). Speed = distance : time; for example, if the cloud goes from –100 pixels on the left to 400 pixels (500 pixels) in 10 seconds, its speed is 50 pixels/s. For user control a button and JavaScript are used: classList.toggle adds or removes a class on the stage, and CSS gives animation-play-state: paused depending on that class. The finished work must be tested: open it in another browser and at phone size, check that the animation does not stop by itself and that the text is readable; if there is a mistake, look at the messages in the console of the browser's developer tools (F12). When the work is done, keep a copy of the code, and do not use other people's pictures or sounds without permission.
In a school play the time each prop and participant enters and leaves the stage is written down in advance, otherwise order on stage breaks down. The director shows a finished scene to other people and asks what was unclear. A complex scene is planned and tested this way.
Directors, stage crews and software testers plan the work and have the finished result tried by others.
Show a poster or notice you made to a friend for 10 seconds, then ask what they remembered and write down which part was unclear.
1<!DOCTYPE html> 2<html lang="uz"> 3<head> 4 <meta charset="utf-8"> 5 <title>Quyosh va bulut</title> 6 <style> 7 .sahna { position: relative; width: 400px; height: 160px; background: #bfe3ff; overflow: hidden; } 8 .quyosh { position: absolute; left: 20px; top: 100px; width: 50px; height: 50px; 9 border-radius: 50%; background: #ffb703; animation: chiq 6s ease-in-out infinite alternate; } 10 .bulut { position: absolute; left: -100px; top: 20px; width: 100px; height: 36px; 11 border-radius: 18px; background: #ffffff; animation: suz 10s linear infinite; } 12 @keyframes chiq { from { top: 100px; } to { top: 10px; } } 13 @keyframes suz { from { left: -100px; } to { left: 400px; } } 14 .toxta .quyosh, .toxta .bulut { animation-play-state: paused; } 15 </style> 16</head> 17<body> 18 <div class="sahna" id="sahna"> 19 <div class="quyosh"></div> 20 <div class="bulut"></div> 21 </div> 22 <button onclick="almashtir()">To‘xtat / davom ettir</button> 23 <script> 24 function almashtir() { 25 document.getElementById("sahna").classList.toggle("toxta"); 26 } 27 </script> 28</body> 29</html>
| Object | Distance | Time | Speed |
|---|---|---|---|
| cloud | 400 – (–100) = 500 pixels | 10 seconds | 50 pixels/s |
| sun | 100 – 10 = 90 pixels | 6 seconds | 15 pixels/s |
“Studio”: groups of three (director, coder, tester) make a scene with 3 objects – for example day and night, a car and a cloud; then they swap roles, test each other's work and write a list of mistakes.