【React】普通H5中Swiper.js的Demo

Swiper官网:

还有其他的效果Effect可以去官网查看

https://swiperjs.com/swiper-api#scrollbar

// Import Swiper React components
import 'swiper/css';

import Image from '../..';

// import 'swiper/css/coverflow-effect';
import { EffectCoverflow, Navigation, Pagination } from 'swiper'; // 导入 Swiper 的模块
import { Swiper, SwiperSlide } from 'swiper/react';

import styles from './index.module.css';


const MyCustomSwiper = () => {
  return (
    <Swiper
      style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}
      // effect="coverflow" // 激活 Coverflow 效果
      modules={[Navigation, Pagination, EffectCoverflow]} // 使用导入的模块
      centeredSlides
      slidesPerView={'auto'}
      spaceBetween={-100} // 卡片之间的间隔
      onSlideChange={() => console.log('slide change')}
      onSwiper={(swiper) => console.log(swiper)}
      // draggable
      coverflowEffect={{
        depth: 100,
        modifier: 1,
        rotate: 50,
        scale: 1,
        slideShadows: false,
        stretch: 10,
      }}
    >
      {[0, 1, 2, 3, 4].map((v, index) => (
        <SwiperSlide key={v}>
          <div
            style={{
              width: '538rpx', // 卡片宽度
              height: '636rpx', // 卡片高度
              backgroundColor: 'red', // 卡片背景色
              borderRadius: '40rpx', // 圆角
              boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)', // 阴影效果
              display: 'flex',
              justifyContent: 'center',
              alignItems: 'center',
              marginLeft: '120rpx'
            }}
          >
            <Image
              className={styles.demoImageCenter}
              src=""
              width={'240px'} // 调整图像宽度
              height={'240px'}
            />
          </div>
        </SwiperSlide>
      ))}
    </Swiper>
  );
};

export default MyCustomSwiper;

![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/166ab7d9272444f19c3b152577b134a8.png

Demo

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值