Write a HTML CSS Javascript code for a website full of as much fun animations as possible
- User
Write a HTML CSS Javascript code for a website full of as much fun animations as possible
- Assistant
Write a HTML CSS Javascript code for a website full of as much fun animations as possible
Sure! Below is a complete, self-contained HTML file that includes multiple fun animations using HTML, CSS, and JavaScript. This example showcases various animated elements, such as bouncing balls, rotating squares, moving text, floating shapes, and interactive animations triggered by user actions.
You can copy the following code into a .html file and open it in your browser to see the animations in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fun Animations Galore!</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: linear-gradient(135deg, #f06, #f79);
font-family: Arial, sans-serif;
height: 100vh;
position: relative;
}
/* Bouncing Ball */
.ball {
width: 50px;
height: 50px;
background-color: #fff;
border-radius: 50%;
position: absolute;
top: 0;
left: 20%;
animation: bounce 2s infinite ease-in-out;
}
@keyframes bounce {
0%, 100% {
top: 0;
animation-timing-function: ease-in;
}
50% {
top: 80vh;
animation-timing-function: ease-out;
}
}
/* Rotating Square */
.square {
width: 50px;
height: 50px;
background-color: #000;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(0deg);
animation: rotate 4s linear infinite;
}
@keyframes rotate {
from {
transform: translate(-50%, -50%) rotate(0deg);
}
to {
transform: translate(-50%, -50%) rotate(360deg);
}
}
/* Moving Text */
.moving-text {
position: absolute;
bottom: 10%;
width: 100%;
text-align: center;
font-size: 2em;
color: #fff;
animation: moveText 5s linear infinite;
}
@keyframes moveText {
0% {
transform: translateX(-100%);
}
50% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
/* Floating Shapes */
.shape {
width: 30px;
height: 30px;
background-color: rgba(255, 255, 255, 0.6);
position: absolute;
border-radius: 50%;
animation: float 6s ease-in-out infinite;
}
@keyframes float {
0% {
transform: translateY(0) scale(1);
opacity: 1;
}
50% {
transform: translateY(-100px) scale(1.5);
opacity: 0.7;
}
100% {
transform: translateY(0) scale(1);
opacity: 1;
}
}
/* Interactive Button */
.interactive-button {
position: absolute;
top: 10%;
right: 10%;
padding: 15px 25px;
background-color: #fff;
color: #f06;
border: none;
border-radius: 25px;
cursor: pointer;
font-size: 1em;
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
transition: transform 0.3s, background-color 0.3s;
}
.interactive-button:hover {
transform: scale(1.1) rotate(10deg);
background-color: #f06;
color: #fff;
}
/* Add more styles as needed */
</style>
</head>
<body>
<!-- Bouncing Ball -->
<div class="ball"></div>
<!-- Rotating Square -->
<div class="square"></div>
<!-- Moving Text -->
<div class="moving-text">Welcome to the Fun Animations Site!</div>
<!-- Floating Shapes -->
<div class="shape" style="top: 20%; left: 30%; animation-delay: 0s;"></div>
<div class="shape" style="top: 40%; left: 70%; animation-delay: 2s;"></div>
<div class="shape" style="top: 60%; left: 50%; animation-delay: 4s;"></div>
<div class="shape" style="top: 80%; left: 20%; animation-delay: 1s;"></div>
<div class="shape" style="top: 10%; left: 80%; animation-delay: 3s;"></div>
<!-- Interactive Button -->
<button class="interactive-button" onclick="triggerAnimation()">Click Me!</button>
<script>
function triggerAnimation() {
// Create a new circle that expands and fades out
const circle = document.createElement('div');
circle.style.width = '20px';
circle.style.height = '20px';
circle.style.backgroundColor = '#fff';
circle.style.borderRadius = '50%';
circle.style.position = 'absolute';
circle.style.left = `${Math.random() * 100}vw`;
circle.style.top = `${Math.random() * 100}vh`;
circle.style.opacity = '1';
circle.style.transition = 'all 1s ease-out';
document.body.appendChild(circle);
// Trigger the animation
setTimeout(() => {
circle.style.width = '100px';
circle.style.height = '100px';
circle.style.opacity = '0';
}, 10);
// Remove the element after animation
setTimeout(() => {
document.body.removeChild(circle);
}, 1010);
}
// Generate multiple floating shapes
function createFloatingShapes() {
const colors = ['#fff', '#ffeb3b', '#4caf50', '#03a9f4', '#e91e63'];
for (let i = 0; i < 20; i++) {
const shape = document.createElement('div');
shape.classList.add('shape');
shape.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
shape.style.left = `${Math.random() * 100}vw`;
shape.style.top = `${Math.random() * 100}vh`;
shape.style.animationDelay = `${Math.random() * 6}s`;
shape.style.width = `${Math.random() * 30 + 20}px`;
shape.style.height = shape.style.width;
document.body.appendChild(shape);
}
}
// Initialize floating shapes
createFloatingShapes();
</script>
</body>
</html>
HTML Structure:
<body> contains various <div> elements representing different animated shapes and a <button> for interactive animation.CSS Animations:
bounce keyframes to move the ball up and down.rotate keyframes.moveText keyframes.float keyframes with different animation delays for randomness.JavaScript Functionality:
triggerAnimation(): When the button is clicked, it creates a new circle at a random position, expands it, fades it out, and then removes it from the DOM.createFloatingShapes(): Generates multiple floating shapes with random colors, sizes, positions, and animation delays to enhance the visual effect.Feel free to customize the animations by:
<div> elements with unique classes and define new animations.background-color, width, height, and other CSS properties to suit your aesthetic preferences.animation-duration, animation-delay, and keyframe percentages to change the speed and behavior of animations.This example provides a foundation for creating a lively and animated website. You can expand upon it by adding more interactive elements, incorporating responsive design, or enhancing animations with advanced techniques.