Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

image continuous changing div react

import React from "react";
import ReactDOM from "react-dom";

import "./styles.css";

class App extends React.Component {
  constructor(props) {
    super(props);
    this.switchImage = this.switchImage.bind(this);
    this.state = {
      currentImage: 0,
      images: [
        "https://images.unsplash.com/photo-1518791841217-8f162f1e1131?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80",
        "https://img.purch.com/w/660/aHR0cDovL3d3dy5saXZlc2NpZW5jZS5jb20vaW1hZ2VzL2kvMDAwLzEwNC84MzAvb3JpZ2luYWwvc2h1dHRlcnN0b2NrXzExMTA1NzIxNTkuanBn",
        "https://d17fnq9dkz9hgj.cloudfront.net/uploads/2012/11/152964589-welcome-home-new-cat-632x475.jpg",
        "https://i.ytimg.com/vi/jpsGLsaZKS0/maxresdefault.jpg"
      ]
    };
  }

  switchImage() {
    if (this.state.currentImage < this.state.images.length - 1) {
      this.setState({
        currentImage: this.state.currentImage + 1
      });
    } else {
      this.setState({
        currentImage: 0
      });
    }
    return this.currentImage;
  }

  componentDidMount() {
    setInterval(this.switchImage, 1000);
  }

  render() {
    return (
      <div className="slideshow-container">
        <img
          src={this.state.images[this.state.currentImage]}
          alt="cleaning images"
        />
      </div>
    );
  }
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Comment

PREVIOUS NEXT
Code Example
Javascript :: <FilterProvider errorr 
Javascript :: code in nested forEach loop- react native 
Javascript :: puppeteer enable location permission 
Javascript :: implement cai webchat in react native 
Javascript :: locak storage for table js 
Javascript :: Get node value in XML using jQuery 
Javascript :: how to make apk in android studio reac native 
Javascript :: smaler div on devices 
Javascript :: react native generate app hash without play console 
Javascript :: unity rotate object to match normal 
Javascript :: JS get 2d array row count 
Javascript :: input search picture jquery 
Javascript :: processing an express form with node-postgres 
Javascript :: angular attach component to body 
Javascript :: how to fix eslint jsx not allowed in js 
Javascript :: vscode coderunner does not find python library 
Javascript :: if property is same group javscript 
Javascript :: button inside popover not viible 
Javascript :: apex express 18 forgot password 
Javascript :: parsing through json without using key value python 
Javascript :: 5.625/2 
Javascript :: react native: how to know th softkey height 
Javascript :: -d {followingjson} curl 
Javascript :: is typescript slower than javascript 
Javascript :: using slice and reduce together in javascript 
Javascript :: get each primary colour and add into an array javascript 
Javascript :: How to check all checkboxes using jQuery? Ask Question 
Javascript :: js remove plus 
Javascript :: Laravel bootstrap 5 install popper.js error 
Javascript :: svlete each index 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =