ReactJS component to make images appear with transition as they load.
Wraps an
img
within a placeholder element and adds a gif loader in between. No more ugly-looking progressively loading images!
This project has also been ported to AngularJS 1.x - ng-image-appear.
npm install react-image-appear --save
yarn add react-image-appear
Import the component and provide the src
with any of the available props.
import ReactImageAppear from 'react-image-appear';
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
animation="zoomIn"
animationDuration="1s"
/>
The image source.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
/>
Classes to be applied to the image.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
className="my-image"
/>
Adds a custom loader to the component. When not provided, applies a default one.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
loader="https://cache.dominos.com/nolo/ca/en/010048/assets/build/images/img/spinner.gif"
/>
Adds custom styling to the loader.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
loaderStyle={{ border: "2px solid red" }}
/>
Adds CSS classes to the loader.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
loaderClass="my-loader"
/>
Adds a placeholder background to the component.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
placeholder
/>
You can override the default placeholder background and add your own by passing an image URL to this prop.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
placeholder="http://getuikit.com/docs/images/placeholder_600x400.svg"
/>
Adds custom styling to the placeholder.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
placeholderStyle={{ border: "2px solid red", backgroundColor: 'black' }}
/>
Adds CSS classes to the placeholder.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
loaderClass="my-placeholder"
/>
Add a CSS3 powered animation to the image as it appears.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
animation="bounceIn"
/>
react-image-appear has the following built-in CSS3 animations -
Specifies the animation duration for the image to appear.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
animation="bounceIn"
animationDuration="1s"
/>
Specifies the timing-function for the CSS3 powered animation.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
animation="bounceIn"
easing="ease-in"
/>
Specifies whether to show the loader or not.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
showLoader={false}
/>
Callback to be called when the image is clicked.
<ReactImageAppear
src="https://newevolutiondesigns.com/images/freebies/tropical-beach-background-8.jpg"
onClick={handleImageClick}
/>
ReactImageAppear uses the jest test runner along with enzyme for easier assertion and manipulation. Run the following command to start the jest test runner -
npm test
Arun Michael Dsouza |
Patrick |
Stefan |
Tim Carr |
---|
If you'd like to help support the development of the project, please consider backing me on Patreon -
MIT Licensed
Copyright (c) 2018 Arun Michael Dsouza (amdsouza92@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.