可以使用 swiper 库实现每屏三个 slide,这个动画的实现思路是什么,比如借助 react-spring 或者 famer-motion ?
这里有个简单的模板。
import { Swiper, SwiperSlide } from 'swiper/react';
import { animated } from '@react-spring/web';
import "swiper/css";
import { Autoplay } from 'swiper/modules';
const data = [
{ id: 1, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'red' },
{ id: 2, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'blue' },
{ id: 3, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'green' },
{ id: 4, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'red' },
{ id: 5, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'blue' },
{ id: 6, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'green' },
{ id: 7, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'red' },
{ id: 8, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'blue' },
{ id: 9, title: '这是标题', icon: 'https://dummyimage.com/80', name: '图标名称', color: 'green' },
];
export const MyCarousel = () => {
return (
<Swiper
spaceBetween={0}
slidesPerView={3}
loop
modules={[Autoplay]}
>
{data.map((item) => (
<SwiperSlide key={item.id} style={{ border: '1px dashed', display: 'flex', justifyContent: 'center' }}>
<animated.div
style={{ background: item.color }}
>
<div>{item.title}</div>
<img src={item.icon} alt='' />
<div>{item.name}</div>
</animated.div>
</SwiperSlide>
))}
</Swiper>
);
};