73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import * as React from "react";
|
|
import Autoplay from "embla-carousel-autoplay";
|
|
|
|
import { Card, CardContent } from "@/ui/card";
|
|
import {
|
|
Carousel,
|
|
CarouselContent,
|
|
CarouselItem,
|
|
} from "@/ui/carousel"; // 注意这里也移除了未使用的导入
|
|
|
|
const imageUrls = [
|
|
"/images/carousel-1.jpg",
|
|
"/images/carousel-2.jpg",
|
|
"/images/carousel-3.jpg",
|
|
"/images/carousel-4.jpg",
|
|
"/images/carousel-5.jpg",
|
|
"/images/carousel-6.jpg",
|
|
"/images/book1.png",
|
|
"/images/header.png",
|
|
"/images/jcdt.png",
|
|
];
|
|
|
|
export function AutoCarouselDemo() {
|
|
return (
|
|
<div className="relative w-full mx-auto">
|
|
|
|
|
|
<Carousel
|
|
opts={{
|
|
loop: true,
|
|
align: "start",
|
|
}}
|
|
plugins={[
|
|
Autoplay({
|
|
delay: 3000,
|
|
stopOnInteraction: false,
|
|
}),
|
|
]}
|
|
className="w-full"
|
|
>
|
|
<CarouselContent className="flex gap-4">
|
|
{imageUrls.map((src, index) => (
|
|
<CarouselItem
|
|
key={index}
|
|
className="basis-1/4 md:basis-1/3 lg:basis-1/4 flex-shrink-0 relative"
|
|
>
|
|
<div
|
|
className="p-1 transition-transform duration-500 hover:scale-105 cursor-pointer"
|
|
style={{
|
|
transform: 'scale(1)',
|
|
transition: 'all 0.5s ease',
|
|
}}
|
|
>
|
|
<div className="overflow-hidden border-none shadow-lg h-120">
|
|
<CardContent className="relative w-full h-full">
|
|
<img
|
|
src={src}
|
|
alt={`Slide ${index + 1}`}
|
|
className="w-full h-full object-cover"
|
|
loading="lazy"
|
|
/>
|
|
</CardContent>
|
|
</div>
|
|
</div>
|
|
</CarouselItem>
|
|
))}
|
|
</CarouselContent>
|
|
|
|
|
|
</Carousel>
|
|
</div>
|
|
);
|
|
} |