Falling snow animation over snowy background creates magic effect. Buit in React JS.
Created
November 11, 2022 21:50
-
-
Save Mohamed-Salah-1/185f7e10e9f790300f624f7359a96264 to your computer and use it in GitHub Desktop.
React JS Falling Snow Animation
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
<div id="root"></div> |
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
const Snowflake = (props) =>{ | |
return( | |
<p className='Snowflake' id={`item${props.id}`} style={props.style}> | |
* | |
</p> | |
) | |
} | |
class Snow extends React.Component { | |
snow=()=>{ | |
let animationDelay = '0s'; | |
let fontSize = '100px'; | |
let arr = Array.from('Snowflakes are awesome!!! They are like little pieces of magic!!! Love snowflakes!!! Snowflakes are awesome!!! They are like little pieces of magic!!! Love snowflakes!!! Snowflakes are awesome!!! They are like little pieces of magic!!! Love snowflakes!!!') | |
return arr.map((el, i)=>{ | |
animationDelay = `${(Math.random()*16).toFixed(2)}s`; | |
fontSize = `${(Math.floor(Math.random()*10) + 10)}px`; | |
let style = { | |
animationDelay, | |
fontSize | |
} | |
return (<Snowflake key={i} id={i} style={style}/>) | |
}) | |
} | |
render(){ | |
return( | |
<div className='App'> | |
{this.snow()} | |
</div> | |
) | |
} | |
} | |
//************************************ | |
ReactDOM.render( | |
<Snow />, | |
document.getElementById('root') | |
); |
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/react/16.8.6/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.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
body { | |
background: url("https://images.unsplash.com/photo-1483043012503-8a8849b4c949?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80") center / cover no-repeat; | |
margin: 0; | |
padding: 0; | |
height: 100vh; | |
} | |
h1{ | |
font-size: 100px; | |
} | |
.App{ | |
display: flex; | |
justify-content: space-between; | |
margin: 0; | |
padding: 0; | |
overflow: hidden; | |
height: 100vh; | |
} | |
.Snowflake { | |
dispalay: inline-block; | |
width: 0.1%; | |
color: #FFFAFA; | |
opacity: 0; | |
font-size: 120px; | |
margin: 0; | |
padding: 0; | |
animation: fall 16s linear infinite; | |
} | |
@keyframes fall { | |
0% { | |
opacity: 0; | |
} | |
3% { | |
opacity: 0.9; | |
} | |
90% { | |
opacity: 0.9; | |
} | |
100% { | |
transform: translate(0, 97vh); | |
opacity: 0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment