CSS3 Transition,Animation and advanced javascriptCSS3 transitions and animations breathe life into web pages by creating smooth and engaging visual effects. From hover effects to complex animated sequences, these features enhance user experience and add flair to your designs.
CSS transitions define how properties change gradually instead of snapping abruptly.
transition-property: CSS property to animate (e.g., background-color, transform)transition-duration: How long the change takes (e.g., 0.5s, 200ms)transition-timing-function: The speed curve (ease, linear, ease-in, ease-out)transition-delay: Delay before starting (e.g., 1s)Shorthand Syntax:
transition: property duration timing-function delay;
Hover over the button to see color and scale change smoothly! π±οΈβ¨
Hover over the box to see it expand and change color seamlessly! π¨
Animations allow you to define multiple stages of movement or styling changes, giving more control and flexibility.
The ball bounces up and down continuously! πβ¨
The spinner rotates endlessly while gently growing and shrinking. π‘π«
Hover to see rotation and pulsing color together! π
transform and opacity.Notice: Experiment with hover, animation, and transition combinations to create interactive designs. Students can modify values and see effects instantly!
Functions are one of the most fundamental building blocks in JavaScript. They allow you to encapsulate code, make it reusable, and create dynamic interactions. Let's explore scope, parameters, and return values step by step!
A function is a block of code designed to perform a specific task. It runs only when called (invoked).
Syntax:
function functionName(parameters) {
// Code to execute
}
Example:
function greet() {
console.log("Hello, world!");
}
greet(); // Output: Hello, world!
Scope determines where variables are accessible.
Global Scope:
let globalVar = "I'm global!";
function showGlobalVar() {
console.log(globalVar); // Accessible
}
showGlobalVar(); // Output: I'm global!
Local Scope:
function showLocalVar() {
let localVar = "I'm local!";
console.log(localVar); // Accessible
}
showLocalVar(); // Output: I'm local!
console.log(localVar); // β Error: localVar is not defined
Block Scope (let/const):
if(true) {
let blockVar = "I'm block scoped!";
console.log(blockVar); // Accessible
}
console.log(blockVar); // β Error
Parameters are placeholders for values passed into functions.
function greet(name) {
console.log(`Hello, ${name}!`);
}
greet("Alice"); // Hello, Alice!
greet("Bob"); // Hello, Bob!
Default Parameters:
function greet(name = "Stranger") {
console.log(`Hello, ${name}!`);
}
greet(); // Hello, Stranger!
The return statement outputs a value from the function.
function add(a, b) {
return a + b;
}
let sum = add(5,3);
console.log(sum); // 8
Return Multiple Values:
function getCoordinates() {
return [10, 20];
}
let [x, y] = getCoordinates();
console.log(x, y); // 10 20
Notice: You can also return objects to return multiple named values.
function getUser() {
return { name:"Alice", age:25 };
}
let user = getUser();
console.log(user.name); // Alice
Concise syntax for writing functions.
const greet = (name) => `Hello, ${name}!`;
console.log(greet("Alice")); // Hello, Alice!
Single expression arrow functions can omit {} and return:
const square = num => num * num;
console.log(square(5)); // 25
Test this example by clicking the button:
CSS animations add life to web pages, while JavaScript allows you to control and trigger animations dynamically. Letβs explore how to combine them!
Key properties:
@keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}
.box {
animation-name: fadeIn;
animation-duration: 2s;
animation-timing-function: ease-in;
animation-delay: 0s;
animation-iteration-count: 1;
}
You can add or remove CSS classes dynamically to trigger animations.
Example: Button Click to Animate a Box
.box.animate {
opacity: 1;
animation: moveRight 2s ease-in-out forwards;
}
@keyframes moveRight {
0% { transform: translateX(0); }
100% { transform: translateX(200px); }
}
JavaScript can directly modify CSS properties.
Example: Dynamic Animation Duration
Start, pause, and resume animations dynamically:
transform and opacity instead of width or height.By combining CSS animations and JavaScript, you can craft interactive, engaging websites. Experiment, test, and let your creativity shine! πβ¨
Websites π
Videos π₯
Websites π
Videos π₯
Websites π
Videos π₯
These resources will help you dive deeper into each topic, offering insights, examples, and practical knowledge. Happy learning! π