Creating a simple HTML screensaver without any text can involve animated shapes, colors, or patterns. Below is an example of a single-page HTML screensaver using CSS animations and JavaScript to create a colorful background with moving circles.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple HTML Screensaver</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #232323;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
collection: 1;
}
.circle {
position: absolute;
border-radius: 50%;
opacity: 0.8;
}
</style>
</head>
<body>
<script>
const numberOfCircles = 20; // Adjust the number of circles
const colors = ['#FF5733', '#33FF57', '#3357FF', '#FF33A1', '#FF33B8', '#A133FF', '#33FFF7'];
for (let i = 0; i < numberOfCircles; i++) {
createCircle();
}
function createCircle() {
const circle = document.createElement('div');
const size = Math.random() * 100 + 20; // Random size between 20 and 120px
const color = colors[Math.floor(Math.random() * colors.length)];
const positionX = Math.random() * window.innerWidth;
const positionY = Math.random() * window.innerHeight;
circle.style.width = `${size}px`;
circle.style.height = `${size}px`;
circle.style.backgroundColor = color;
circle.style.left = `${positionX}px`;
circle.style.top = `${positionY}px`;
circle.classList.add('circle');
document.body.appendChild(circle);
animateCircle(circle);
}
function animateCircle(circle) {
const animationDuration = Math.random() * 5 + 5; // Random duration between 5s and 10s
const translateX = Math.random() * 200 - 100; // Random x direction
const translateY = Math.random() * 200 - 100; // Random y direction
circle.animate(
[
{ transform: 'translate(0, 0)' },
{ transform: `translate(${translateX}px, ${translateY}px)` },
],
{
duration: animationDuration * 1000,
iterations: Infinity,
easing: 'ease-in-out'
}
);
}
</script>
</body>
</html>
Explanation:
-
HTML Structure: The body contains the JavaScript that generates animated circles, so no additional HTML elements are needed.
-
CSS Styles:
- The body is styled to remove margins and to use flexbox for centering content, but it primarily relies on positioning for animated circles.
- The
.circle class creates circular shapes with rounded corners via border-radius.
-
JavaScript:
- A specified number of circles are created with randomized sizes, colors, and positions on the screen.
- The animation function creates a random path for each circle's movement.
- Circles continually transition between starting and target positions using CSS animations.
Usage:
Copy the code into an HTML file and open it in a web browser. You will see animated, colorful circles moving across the screen, creating a visually intriguing screensaver effect.