Certainly! Below is a simple example of a single-page HTML screensaver that uses CSS animations and JavaScript to create visually engaging effects without any text. You can copy this code into an HTML file and open it in your browser to see the screensaver in action.
<!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: #000;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
animation: fadeIn 2s both;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.dot {
position: absolute;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.8);
animation: move 4s infinite ease-in-out;
}
@keyframes move {
0% {
transform: translate(0, 0);
}
25% {
transform: translate(calc(100vw - 50px), 0);
}
50% {
transform: translate(calc(100vw - 50px), calc(100vh - 50px));
}
75% {
transform: translate(0, calc(100vh - 50px));
}
100% {
transform: translate(0, 0);
}
}
</style>
</head>
<body>
<script>
function createDot() {
const dot = document.createElement('div');
const size = Math.random() * 30 + 10; // Random size between 10px and 40px
dot.className = 'dot';
dot.style.width = `${size}px`;
dot.style.height = `${size}px`;
dot.style.top = `${Math.random() * 100}vh`;
dot.style.left = `${Math.random() * 100}vw`;
dot.style.opacity = Math.random();
// Animate the dot
dot.style.animationDuration = `${Math.random() * 5 + 2}s`; // Random duration between 2s and 7s
document.body.appendChild(dot);
// Remove the dot after animation ends
dot.addEventListener('animationend', () => {
dot.remove();
});
}
// Create multiple dots at intervals
setInterval(createDot, 500);
</script>
</body>
</html>
Explanation:
- HTML Structure: It's a simple structure with a
body tag that contains all the content created via JavaScript.
- CSS Styles:
- The body has a black background and uses Flexbox to center elements.
- Each
dot is styled to be a circle and has a white color with some transparency.
- Keyframe animations (
fadeIn for the body and move for the dots) create the animation effects.
- JavaScript Functionality:
- The
createDot function generates a dot with a random size, position, opacity, and animation duration.
- Dots will be created every 500 milliseconds and removed from the DOM once their animation ends.
To see the screensaver, save this code as an .html file and open it in a web browser. Enjoy your animated screensaver!