I need help figuring out how to layer two different animations on my website. Specifically, I want to create an effect where twinkling stars are in the background with a moving moon animation layered on top of them. However, when I try to implement this, the moon animation covers up the stars and is not positioned correctly. As a beginner in HTML, I would appreciate any guidance or suggestions. Thanks in advance!
@keyframes moon {
0% {
box-shadow: -150px 0px 0px 0px white;
transform: rotate(-10deg);
}
50% {
box-shadow: 0px 0px 0px 0px white;
}
100% {
box-shadow: 150px 0px 0px 0px white;
transform: rotate(10deg);
}
z-index: -1;
position: relative;
}
@keyframes move-twink-back {
from {
background-position: 0 0;
}
to {
background-position: -10000px 5000px;
}
}
@-webkit-keyframes move-twink-back {
from {
background-position: 0 0;
}
to {
background-position: -10000px 5000px;
}
}
@-moz-keyframes move-twink-back {
from {
background-position: 0 0;
}
to {
background-position: -10000px 5000px;
}
}
@-ms-keyframes move-twink-back {
from {
background-position: 0 0;
}
to {
background-position: -10000px 5000px;
}
}
.stars,
.twinkling {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
}
.stars {
background: #000 url(http://www.script-tutorials.com/demos/360/images/stars.png) repeat top center;
z-index: -1;
}
.twinkling {
background: transparent url(http://www.script-tutorials.com/demos/360/images/twinkling.png) repeat top center;
z-index: 0;
-moz-animation: move-twink-back 200s linear infinite;
-ms-animation: move-twink-back 200s linear infinite;
-o-animation: move-twink-back 200s linear infinite;
-webkit-animation: move-twink-back 200s linear infinite;
animation: move-twink-back 200s linear infinite;
}
html {
z-index: -1;
position: relative;
background-image: linear-gradient(black 80%, #041931, #fff);
background-repeat: no-repeat;
height: 45%;
}
body {
font-family: 'Manrope', sans-serif;
background: none;
}
div {
background: none;
z-index: 1;
}
.moon {
z-index: -1;
position: relative;
width: 10rem;
height: 10rem;
background: #0a0a0a;
margin: 1rem auto;
animation: moon 20s linear infinite alternate;
border-radius: 50%;
box-shadow: inset -10rem 0 whitesmoke;
transform: rotate(-10deg);
}
<html>
<style>
div {
margin: 10%;
}
</style>
<body>
<h1 id="text">
<center> Welcome to my Site! </center>
</h1>
<div class="moon"></div>
<div class="stars"></div>
<div class="twinkling"></div>
<div class="maintext">
<h2>This is text below the animations</h2>
</div>
<script type="text/javascript">
setTimeout(function() {
$('.moon').css("animation-play-state", "paused");
}, 20000)
</script>
</body>
</html>