<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
</div>
<div class="star"></div>
<section>
<span></span>
</section>
<div class="class">
<h1>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quos minus voluptatum exercitationem voluptates, deleniti nisi hic magni doloremque vel iure rem natus eius nobis aliquid perferendis maiores architecto beatae qui?</h1>
</div>
<script src="script.js"></script>
</body>
</html>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
background: url(Фон.jpg);
overflow: hidden;
height: 100vh;
width: 100%;
}
span {
position: absolute;
width: 4px;
height: 4px;
background: #fff;
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(255, 255, 255, .1),
0 0 0 8px rgba(255, 255, 255, .1),
0 0 20px rgba(255, 255, 255, 1);
animation: animate 3s linear infinite;
right: 50%;
top: 0;
}
span:before {
content: '';
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 300px;
height: 1px;
background: linear-gradient(90deg, #fff, transparent);
}
@keyframes animate {
0% {
transform: rotate(-45deg) translateX(0);
}
70% {
opacity: 1;
}
100% {
transform: rotate(-45deg) translateX(-1000px);
opacity: 0;
}
}
@keyframes animateBg {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
}
document.addEventListener("DOMContentLoaded", function() {
const star = document.querySelector('span');
star.style.top = '0px';
});
let lastScrollTop = 0;
window.addEventListener('scroll', function() {
const st = window.pageYOffset || document.documentElement.scrollTop;
if (st > lastScrollTop) {
const star = document.querySelector('span');
const yPos = parseInt(star.style.top) + 1;
star.style.top = yPos + 'px';
} else if (st < lastScrollTop) {
const star = document.querySelector('span');
const yPos = parseInt(star.style.top) - 1;
star.style.top = yPos + 'px';
}
lastScrollTop = st;
});
Как сделать так, чтобы звезда падала только при скролле страницы?