Responsive, css transitions based image slider/gallery/carousel for react.js

  • By Azim Gadzhiagayev
  • Last update: Apr 13, 2022
  • Comments: 5

React image slider

Responsive, css transitions based image slider/gallery/carousel for react.js

Installation

npm install react-image-slider

and add css file from ./node_modules/react-image-slider/lib/image-slider.css

Example

import React from 'react';
import Slider from 'react-image-slider';

export default React.createClass({
  render() {
    const images = [
      '//placehold.it/600/1abc9c',
      '//placehold.it/600/3498db',
      '//placehold.it/600/2ecc71',
      '//placehold.it/600/9b59b6',
      '//placehold.it/600/f1c40f',
      '//placehold.it/600/e74c3c',
      '//placehold.it/600/e67e22',
    ];

    return (
      <Slider images={images} isInfinite delay={5000}>
        {images.map((image, key) => <div key={key}><img src={image} /></div>)}
      </Slider>
    );
  }
});

Demo

In order to run demo, execute:

cd example
npm install
npm start

and then navigate to http://localhost:8080

License

The MIT License (MIT)

Copyright (c) 2016 React Image Slider <[email protected]>

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.

Github

https://github.com/azimgd/react-image-slider

Comments(5)

  • 1

    Issue with Scrollviews

    First of all thank you for the slider. There is some issues I ran into. Once you set up the slider within a scrollview. The usability gets bad because of horizontal and vertical movements

  • 2

    TypeError: Cannot read property 'shape' of undefined

    × TypeError: Cannot read property 'shape' of undefined ./node_modules/react-image-slider/lib/ImageSlider.js C:/Users/elad/Desktop/netflix/netflix-rebuild/node_modules/react-image-slider/lib/ImageSlider.js:192 189 | return Slider; 190 | }(_react2.default.Component); 191 |

    192 | Slider.propTypes = _react2.default.PropTypes.shape({ 193 | visibleItems: _react.PropTypes.number.isRequired, 194 | images: _react.PropTypes.array.isRequired, 195 | delay: _react.PropTypes.number.isRequired, View compiled webpack_require C:/Users/elad/Desktop/netflix/netflix-rebuild/webpack/bootstrap 2cb67855e5e85d992c20:678 675 | }; 676 | 677 | // Execute the module function 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); 679 | 680 | // Flag the module as loaded 681 | module.l = true; View compiled fn C:/Users/elad/Desktop/netflix/netflix-rebuild/webpack/bootstrap 2cb67855e5e85d992c20:88 85 | console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId); 86 | hotCurrentParents = []; 87 | } 88 | return webpack_require(request); 89 | }; 90 | var ObjectFactory = function ObjectFactory(name) { 91 | return {

  • 3

    Cannot read property 'shape' of undefined

    Uncaught TypeError: Cannot read property 'shape' of undefined
        at Object.defineProperty.value (ImageSlider.js:192)
        at __webpack_require__ (bootstrap 30c3825455a6dbf34f0d:712)
        at fn (bootstrap 30c3825455a6dbf34f0d:117)
        at Object.<anonymous> (image.js:5)
        at __webpack_require__ (bootstrap 30c3825455a6dbf34f0d:712)
        at fn (bootstrap 30c3825455a6dbf34f0d:117)
        at Object.defineProperty.value (single.js:4)
        at __webpack_require__ (bootstrap 30c3825455a6dbf34f0d:712)
        at fn (bootstrap 30c3825455a6dbf34f0d:117)
        at Object.defineProperty.value (hotels.js:15)
    
    

    Copied the example code from docs

  • 4

    Can only update a mounted or mounting component.

    Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. ...

    componentWillMount() { const images = (this.props.images || []).map((image, count) => { return image + ?rscver${count}; }); this.setState({images}); }

  • 5

    Performance/Unmount issue

    When I navigate somewhere else and the slider gets unmounted the animate interval wont stop.

    FIX:

    componentWillUnmount() {
        window.removeEventListener('resize', this.setVisibleItems.bind(this, this.props.visibleItems));
        if (this.state.interval) {
          clearInterval(this.state.interval);
          this.setState({ interval: null });
        }  
      }