Sure! Below is a simple single-page HTML screensaver that features animated circles of different colors floating and changing size randomly. You can copy and paste this code into an HTML file, and when you open it in a web browser, you will see the screensaver effect.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Screensaver</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: black;
}
.circle {
position: absolute;
border-radius: 50%;
opacity: 0.7;
animation: float 4s infinite ease-in-out;
}
@keyframes float {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-30px);
}
100% {
transform: translateY(0);
}
}
</style>
</head>
<body>
<script>
const colors = ['#FF5733', '#33FF57', '#3357FF', '#F1C40F', '#9B59B6', '#E67E22', '#2ECC71'];
const numCircles = 30;
function createCircle() {
const circle = document.createElement('div');
const size = Math.random() * 50 + 20; // Random size from 20 to 70
const left = Math.random() * window.innerWidth; // Random position
const top = Math.random() * window.innerHeight;
circle.className = 'circle';
circle.style.width = `${size}px`;
circle.style.height = `${size}px`;
circle.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
circle.style.left = `${left}px`;
circle.style.top = `${top}px`;
circle.style.animationDuration = `${Math.random() * 3 + 2}s`; // Random animation duration
document.body.appendChild(circle);
}
for (let i = 0; i < numCircles; i++) {
createCircle();
}
</script>
</body>
</html>
Explanation:
- The
body is styled with a black background, and overflow is hidden to prevent scrollbars.
- Circles are created using
<div> elements styled with CSS to have a border-radius of 50%, making them round.
- A random color, size, and position are assigned to each circle, and they float up and down through a CSS animation defined in the
@keyframes float.
- The script creates a specified number of circles (
numCircles) and appends them to the body.
You can modify the number of circles and their color using the colors array or other CSS properties. Make sure to save this code in a file with a .html extension and open it in a web browser to see the screensaver effect in action!