Skip to content

Instantly share code, notes, and snippets.

@zachshallbetter
Last active March 21, 2023 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachshallbetter/ff5798370f7e60cef3f199e7fe8b9290 to your computer and use it in GitHub Desktop.
Save zachshallbetter/ff5798370f7e60cef3f199e7fe8b9290 to your computer and use it in GitHub Desktop.
JSX Carousel
import React from 'react';
import Carousel from "./Carousel";
const images = [
{ src: "https://images.pexels.com/photos/3635300/pexels-photo-3635300.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", alt: "Image 1" },
{ src: "https://images.pexels.com/photos/315938/pexels-photo-315938.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", alt: "Image 2" },
{ src: "https://images.pexels.com/photos/388417/pexels-photo-388417.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1", alt: "Image 3" },
];
function App() {
const renderOverlay = (index) => (
<div
style={{
position: "absolute",
bottom: 0,
left: 0,
backgroundColor: "rgba(0, 0, 0, 0.5)",
color: "#fff",
padding: "10px",
fontSize: "1.2rem",
}}
>
{`Image ${index + 1}`}
</div>
);
return (
<div className="App">
<h1>Carousel Demo</h1>
<Carousel
images={images}
autoplay={true}
delay={3000}
fadeDuration={1000}
overlay={renderOverlay}
/>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment