react 轮番图库swiper

20 篇文章 0 订阅
13 篇文章 1 订阅

相关地址

github
官方demo
api
swiper的react使用文档

实例

import React from 'react'
//引入核心和组件
import SwiperCore, {Pagination,EffectCoverflow } from 'swiper';
import { Swiper, SwiperSlide} from "swiper/react";
//引入样式
import "swiper/swiper.scss";
import "swiper/components/scrollbar/scrollbar.scss";
import "swiper/components/pagination/pagination.scss";
//加载
SwiperCore.use([Pagination,EffectCoverflow]);

function Test3(props) {
    return (
        <div style={{width:500,height:500,border:'1px solid black',margin:'0 auto'}}>
            <Swiper
                centeredSlides={true}  //居中
                pagination={{
                    clickable: true//翻页是否可点击
                }}
                loop={true} //是否循环
                effect="coverflow" //轮番图效果
                spaceBetween={50}  //间距
                slidesPerView={3}  //可预览的数量
                onSlideChange={() => console.log('slide change')} //变化事件
                onSwiper={(swiper) => console.log(swiper)}
            >
                <SwiperSlide><div style={{background:'red'}}>aaa</div></SwiperSlide>
                <SwiperSlide><div style={{background:'blue'}}>aaa</div></SwiperSlide>
                <SwiperSlide><div style={{background:'green'}}>aaa</div></SwiperSlide>
            </Swiper>
        </div>

    )
}
export default Test3

实例效果

在这里插入图片描述

文档要点

  • < Swiper >< /Swiper > 组件的所有属性从哪看
    Swiper props
    react组件接受所有的Swiper 参数作为组件的属性,外加下面这几个,同时所有的事件都加上了on前缀,比如原来的slideChange换成了onSlideChange
    在这里插入图片描述
  • 翻页属性在哪:在这里
pagination={{
      clickable: true//翻页是否可点击
}}
  • demo里面全都是纯html的我怎么用
    把属性抄过来就行,比如我实例中就是抄袭的 effect: 'coverflow',
 var swiper = new Swiper('.swiper-container', {
      effect: 'coverflow',
      grabCursor: true,
      centeredSlides: true,
      slidesPerView: 'auto',
      coverflowEffect: {
        rotate: 50,
        stretch: 0,
        depth: 100,
        modifier: 1,
        slideShadows: true,
      },
      pagination: {
        el: '.swiper-pagination',
      },
    });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值