Creating a simple single-page HTML screensaver without any text can be done using HTML, CSS, and a bit of JavaScript for animations. Below is an example of a screensaver-like effect featuring animated circles that randomly move around the screen.
<!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%;
}
</style>
</head>
<body>
<script>
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function createCircle() {
const circle = document.createElement('div');
const size = getRandomInt(20, 100);
const left = getRandomInt(0, window.innerWidth - size);
const top = getRandomInt(0, window.innerHeight - size);
const color = `hsl(${getRandomInt(0, 360)}, 100%, 50%)`;
circle.className = 'circle';
circle.style.width = `${size}px`;
circle.style.height = `${size}px`;
circle.style.backgroundColor = color;
circle.style.left = `${left}px`;
circle.style.top = `${top}px`;
document.body.appendChild(circle);
animateCircle(circle, size);
}
function animateCircle(circle, size) {
const speedX = getRandomInt(2, 5) * (Math.random() < 0.5 ? 1 : -1);
const speedY = getRandomInt(2, 5) * (Math.random() < 0.5 ? 1 : -1);
function move() {
const rect = circle.getBoundingClientRect();
if (rect.left + speedX < 0 || rect.right + speedX > window.innerWidth) {
speedX *= -1;
}
if (rect.top + speedY < 0 || rect.bottom + speedY > window.innerHeight) {
speedY *= -1;
}
circle.style.left = `${rect.left + speedX}px`;
circle.style.top = `${rect.top + speedY}px`;
requestAnimationFrame(move);
}
move();
}
for (let i = 0; i < 20; i++) {
createCircle();
}
</script>
</body>
</html>
Explanation
-
Structure:
- The code starts with a simple HTML structure, including a
head and body.
-
Styling:
- The body has no margin, hidden overflow, and a black background to simulate a screensaver.
-
JavaScript:
- The JavaScript generates circles of random sizes and colors.
- Circles are positioned randomly on the screen and are animated to bounce around by changing their position while checking for boundary collisions.
How to Use
- Copy the code above.
- Paste it into a new
.html file (e.g., screensaver.html).
- Open the file in a web browser to see the screensaver effect.
Feel free to adjust the number of circles, their sizes, and the speed of animation to customize the screensaver further!