A Pen by Dustin Miller on CodePen.
Created
August 26, 2024 04:30
-
-
Save spdustin/9bfb41627c98de8ee203444383c77eeb to your computer and use it in GitHub Desktop.
Just rain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please, reload the page if it doesn't works properly <3 | |
// See the console to check the number of <hr> tags | |
let hrElement; | |
let counter = 500; | |
for (let i = 0; i < counter; i++) { | |
hrElement = document.createElement("HR"); | |
if (i == counter - 1) { | |
hrElement.className = "thunder"; | |
} else { | |
hrElement.style.left = Math.floor(Math.random() * window.innerWidth) + "px"; | |
hrElement.style.animationDuration = 0.3 + Math.random() * 0.3 + "s"; | |
hrElement.style.animationDelay = Math.random() * 5 + "s"; | |
} | |
document.body.appendChild(hrElement); | |
} | |
console.log( | |
"There are " + | |
document.querySelectorAll("hr").length + | |
" <hr> tags in this project :)" | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
} | |
:root { | |
--thunder-duration: 7s; | |
--thunder-delay: 13s; | |
} | |
body { | |
background-image: linear-gradient(to bottom, #030420, #000000 70%); | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
width: 100vw; | |
height: 100vh; | |
overflow: hidden; | |
} | |
hr.thunder { | |
border: unset; | |
position: absolute; | |
width: 100vw; | |
height: 100vh; | |
animation-name: thunder; | |
animation-duration: var(--thunder-duration); | |
animation-timing-function: linear; | |
animation-delay: var(--thunder-delay); | |
animation-iteration-count: infinite; | |
} | |
hr:not(.thunder) { | |
width: 50px; | |
border-color: transparent; | |
border-right-color: rgba(255, 255, 255, 0.7); | |
border-right-width: 50px; | |
position: absolute; | |
bottom: 100%; | |
transform-origin: 100% 50%; | |
animation-name: rain; | |
animation-duration: 1s; | |
animation-timing-function: linear; | |
animation-iteration-count: infinite; | |
} | |
@keyframes rain { | |
from { | |
filter: opacity(1); | |
transform: rotate(105deg) translateX(0); | |
} | |
to { | |
filter: opacity(0); | |
transform: rotate(105deg) translateX(calc(100vh + 20px)); | |
} | |
} | |
@keyframes thunder { | |
0% { | |
background-color: transparent; | |
} | |
1% { | |
background-color: white; | |
} | |
2% { | |
background-color: rgba(255, 255, 255, 0.8); | |
} | |
8% { | |
background-color: transparent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment