Last active
February 21, 2020 12:36
-
-
Save SergioGeeK7/8820ab8bf0fdbb18db6b3b22885ddb1d to your computer and use it in GitHub Desktop.
Loading Indicator
This file contains hidden or 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
/* CSS */ | |
.image{ | |
width: 250px; | |
height: 250px; | |
display: block; | |
} | |
.image-loading { | |
position: static; | |
overflow: hidden; | |
animation: placeholderShimmer 2s linear; | |
animation-iteration-count: infinite; | |
background-color: #ffffff !important; | |
background-image: linear-gradient( | |
to right, | |
rgba(0, 0, 0, 0.08) 0%, | |
rgba(0, 0, 0, 0.15) 15%, | |
rgba(0, 0, 0, 0.08) 30% | |
); | |
background-size: 1200px 100%; | |
} | |
@keyframes placeholderShimmer { | |
0% { | |
background-position: -1200px 0; | |
} | |
100% { | |
background-position: 1200px 0; | |
} | |
} | |
/* source: https://semantic-ui.com/ */ |
This file contains hidden or 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
// image.js | |
import React from "react"; | |
export default class Image extends React.PureComponent { | |
state = { | |
loaded: false | |
}; | |
onLoad = () => { | |
this.setState({loaded: true}); | |
}; | |
render() { | |
const {loaded} = this.state; | |
const {className, ...props} = this.props; | |
const loadingClassName = loaded ? "" : "image-loading"; | |
return ( | |
<img | |
{...props} | |
onLoad={this.onLoad} | |
className={`${loadingClassName} ${className}`} | |
/> | |
); | |
} | |
} |
This file contains hidden or 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
// index.js | |
<div className="gallery-container"> | |
<Image src="" className="image"/> | |
<Image src="" className="image"/> | |
<Image src="" className="image"/> | |
<Image src="" className="image"/> | |
<Image src="" className="image"/> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment