NCO (Cyber Olympiad) /Software Applications & Programming

Animations and Transitions

Presentations (MS PowerPoint) · free study notes

Animations & Transitions

Software Applications & Programming – NCO Cyber Olympiad

Think of animations as a movie of a picture that changes over time.


1. What Are Animations?

Concept Everyday Analogy Short Sentence
Animation A flip‑book that shows a cat walking when you flip pages. It shows movement by changing one frame to another.
Frame A single photo in the flip‑book. One still image that is part of the whole picture.
Frame rate How fast you flip the pages. The speed at which frames change (e.g., 30 frames per second).

2. How Do Animations Work in Code?

Frame 1 → Frame 2 → Frame 3 → … → Frame N
  1. Create the frames – draw or load images.
  2. Set a timer – decide how long each frame lasts.
  3. Show the frames – display each one in order.

3. Transitions vs. Animations

Feature Transition Animation
Purpose Smooth change between two states (e.g., opening a menu). Continuous movement within one state (e.g., a button spinning).
Trigger Usually a user action (click, hover). Can be automatic or user‑initiated.
Result Looks like one thing morphs into another. Looks like a moving picture.

4. Simple Example – Moving a Box

<!-- HTML -->
<div id="box"></div>
/* CSS */
#box {
  width: 50px; height: 50px;
  background: teal;
  position: relative;
  left: 0;
  transition: left 2s;   /* Transition: move left over 2 seconds */
}

#box.move {
  left: 200px;          /* New position */
}
// JavaScript – add class on click
document.getElementById('box').addEventListener('click', function() {
  this.classList.toggle('move');
});

What happens?

  1. The box starts at the left side.
  2. Click → class move is added.
  3. CSS transition slides the box to the right over 2 s.

5. Key Properties for CSS Transitions

Property What It Does Tiny Example
transition-property Which style will change (e.g., background-color). transition-property: background-color;
transition-duration How long the change takes. transition-duration: 0.5s;
transition-timing-function Speed pattern (ease, linear). transition-timing-function: ease-in;
transition-delay Wait before starting. transition-delay: 1s;

6. JavaScript Animations

let box = document.getElementById('box');
let pos = 0;
function move() {
  pos += 5;
  box.style.left = pos + 'px';
  if (pos < 200) requestAnimationFrame(move);
}
move();

Using requestAnimationFrame keeps the motion smooth and efficient.


7. Common Uses

Use Example
Buttons Fade in when hovered.
Modals Slide up from the bottom.
Carousels Rotate images automatically.
Games Animate characters or effects.

8. Tips for Beginners

  1. Start small. Animate one property first.
  2. Use transition for simple effects.
  3. Test on a browser (Chrome, Firefox).
  4. Keep performance in mind. Too many heavy animations can slow the page.

9. Quick Check

  1. What is a frame in animation?
  2. How do you make a box slide to the right with CSS?
  3. Which JavaScript function helps create smooth animations?

Remember: Animations make interfaces feel alive, while transitions help users understand the change in state. Keep them subtle, and always test on real devices!

Your note

Page 1

Doubt hai is topic me?

Free AI teacher se poocho — 24/7, step by step.