Open In App

React-Bootstrap Carousel Individual Item Intervals

Last Updated : 02 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

React-Bootstrap Carousel Individual Item Intervals is an attribute of the React Bootstrap component used to set a duration for individual images present in the corousel. By using this, we can set a different duration for all images present in the carousel component.

Props

  • Interval: It is used to specify duration for each Carousel Component. Time should be in milliseconds.

Syntax:

<Carousel.Item interval={*}>

Note: Replace * with time in milliseconds

Example 1: This example explains multiple Corousel Components with 500 milliseconds.

Javascript




// App.js
import React, { useState } from 'react';
import 'bootstrap/dist/css/bootstrap.css';
import Carousel from 'react-bootstrap/Carousel';
  
export default function App() {
    const [index, setIndex] = useState(0);
    const handleSelect = (selectedIndex) => {
        setIndex(selectedIndex);}
    return (
        <div style={{ display: 'block',
                      width: 800,
                      padding: 30}}>
            <h2 style={{ color: 'green' }}>
                GeeksforGeeks
            </h2>
            <h2>
                React-Bootstrap Carousel
                Individual Item Intervals
            </h2>
            <Carousel activeIndex={index}
                      onSelect={handleSelect}>
                <Carousel.Item interval={500}>
                    <img className="d-block w-100"
                         src=
                         alt="JAVA" />
                </Carousel.Item>
                <Carousel.Item interval={500}>
                    <img className="d-block w-100"
                         src=
                         alt="HTML" />
                </Carousel.Item>
                <Carousel.Item interval={500}>
                    <img className="d-block w-100"
                         src=
                         alt="Angular" />
                </Carousel.Item>
            </Carousel>
        </div>
)}


Output:

Recording-2023-10-06-at-014539

Example 2: This example explains multiple Corousel Components with 1500 milliseconds.

Javascript




// App.js
import React from 'react';
import 'bootstrap/dist/css/bootstrap.css';
import Carousel from 'react-bootstrap/Carousel';
  
export default function App() {
  
    return (
        <div style={{
             display: 'block',
             width: 800,
             padding: 30}}>
            <h2 style={{ color: 'green' }}>
                GeeksforGeeks
            </h2>
            <h2>
                React-Bootstrap Carousel
                Individual Item Intervals
            </h2>
            <Carousel >
                <Carousel.Item interval={1500}>
                    <img className="d-block w-100"
                         src=
                         alt="One" />
                    <Carousel.Caption>
                        <h3>Label for first slide</h3>
                        <p>Sample Text for Image One</p>
                    </Carousel.Caption>
                </Carousel.Item>
                <Carousel.Item interval={500}>
                    <img className="d-block w-100"
                         src=
                         alt="Two" />
                    <Carousel.Caption>
                        <h3>Label for second slide</h3>
                        <p>Sample Text for Image Two</p>
                    </Carousel.Caption>
                </Carousel.Item>
            </Carousel>
        </div>
)


Output

Recording-2023-10-06-at-014836



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads