Some rain drops generated in JS through some random values (left and top position). Those drops are then animated in CSS from top to bottom (simple infinite animation).
Last active
January 10, 2020 11:56
-
-
Save osde8info/cc9ee71ca7324d79aecdd521813f05b0 to your computer and use it in GitHub Desktop.
SLOW CSS 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
<section class="rain"></section> |
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
// number of drops created. | |
var nbDrop = 44; | |
// function to generate a random number range. | |
function randRange( minNum, maxNum) { | |
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum); | |
} | |
// function to generate drops | |
function createRain() { | |
for( i=1;i<nbDrop;i++) { | |
var dropLeft = randRange(0,1600); | |
var dropTop = randRange(-1000,1400); | |
$('.rain').append('<div class="drop" id="drop'+i+'"></div>'); | |
$('#drop'+i).css('left',dropLeft); | |
$('#drop'+i).css('top',dropTop); | |
} | |
} | |
// Make it rain | |
createRain(); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
html { | |
height: 100%; | |
} | |
body { | |
background: #0d343a; | |
overflow: hidden; | |
} | |
.drop { | |
background: -moz-linear-gradient( | |
top, | |
rgba(13, 52, 58, 1) 0%, | |
rgba(255, 255, 255, 0.6) 100% | |
); | |
width: 1px; | |
height: 89px; | |
position: absolute; | |
bottom: 200px; | |
animation: fall 4s linear infinite; | |
} | |
/* animate the drops*/ | |
@-webkit-keyframes fall { | |
to { | |
margin-top: 900px; | |
} | |
} | |
@-moz-keyframes fall { | |
to { | |
margin-top: 900px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment