Creating a simple HTML screensaver without any text can be achieved using pure HTML, CSS, and JavaScript. Below is an example of a single-page screensaver that features animated colorful circles that move around the screen. You can copy this code into an HTML file and open it in your web browser to see the effect.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Screensaver</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: black;
}
.circle {
position: absolute;
border-radius: 50%;
animation: move 5s linear infinite;
}
@keyframes move {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(calc(100vw - 100px), calc(100vh - 100px));
}
}
/* Random colors for circles */
@keyframes changeColor {
0% { background-color: red; }
25% { background-color: blue; }
50% { background-color: green; }
75% { background-color: purple; }
100% { background-color: orange; }
}
</style>
</head>
<body>
<script>
function createCircle() {
const circle = document.createElement('div');
const size = Math.random() * 60 + 20; // Circle size between 20px and 80px
const left = Math.random() * window.innerWidth; // Random starting left position
const top = Math.random() * window.innerHeight; // Random starting top position
circle.className = 'circle';
circle.style.width = `${size}px`;
circle.style.height = `${size}px`;
circle.style.left = `${left}px`;
circle.style.top = `${top}px`;
circle.style.backgroundColor = `hsl(${Math.random() * 360}, 100%, 50%)`; // Random color
circle.style.animationDuration = `${Math.random() * 4 + 3}s`; // Random duration between 3 and 7 seconds
circle.style.animationName = 'move, changeColor';
circle.style.animationIterationCount = 'infinite, infinite';
document.body.appendChild(circle);
// Remove the circle after its animation duration
setTimeout(() => {
circle.remove();
}, 7000);
}
function generateCircles() {
const numberOfCircles = 10; // Change this value for more or fewer circles
for (let i = 0; i < numberOfCircles; i++) {
createCircle();
}
}
// Generate new circles every second
setInterval(generateCircles, 1000);
</script>
</body>
</html>
How It Works:
- HTML Structure: The page only contains the
<body> element where the circles will be appended.
- CSS Styles: A
circle class defines the style for the animated circles. @keyframes are used to handle the movement and color changes of the circles.
- JavaScript Logic:
- The
createCircle function generates a circle with a random size and color, places it at a random position, and assigns a random animation duration for movement and color change.
- The
generateCircles function creates a specified number of circles every second.
- Circles are automatically removed after 7 seconds to keep the page clean.
You can modify the number of circles, animation duration, and CSS styles to customize your screensaver as desired.