0.0.2 • Published 9 months ago

swiper-react-component v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

swiper-react-component,swiper

description

基于支持useState,useRef,useEffect等hooks的react版本的轮播组件,有左右和上下轮播方向。

支持左右点击箭头切换,也可以点击下方指示器切换。

支持鼠标左键点击item项后滑动切换。支持鼠标滚动切换。

具体配置、事件、插槽可看下方详细文档

组件使用

  import { useState } from 'react'
  import SwiperReact from 'swiper-react-component'

  function App() {

    const list = [
      {
        id: 1,
        title: 'title1',
        content: 'content1'
      },
      {
        id: 2,
        title: 'title2',
        content: 'content2'
      },
      {
        id: 3,
        title: 'title3',
        content: 'content3'
      }
    ]
    
    return (
      <>
      <SwiperReact height={300} width={600} delay={ 3000 } mouseScroll>
        {
          list.map(item=>{
            return <div key={ item.id } style={{ height: "100%",width: "100%",background: "#99A9BF",display: 'flex',alignItems: 'center',justifyContent:"center"}}>
              { item.content }
            </div>
          })
        }
      </SwiperReact>
      </>
    )
}

export default App

Properties

propertytypedefaultdescription
directionStringhorizontal当前轮播的方向,默认为horizontal水平,vertical为垂直
autoplayBooleantrue是否自动播放轮播
delayNumber3000自动播放间隔,单位毫秒,默认3秒
indicatorBooleantrue是否显示轮播底部指示器
mouseSliderBooleanfalse是否开启鼠标点击轮播项左右滑动切换
triggerMoveNumbernull鼠标点击轮播项左右滑动切换的触发值,默认为滑动该容器1/2.5宽度或者高度切换
mouseScrollBooleanfalse是否开启鼠标滚轮切换轮播,默认不开启
hoverStopBooleantrue鼠标悬停时暂停轮播,默认为true
arrowStringalways左右切换箭头的显示形式,默认一直显示,值为always、hover、none
heightNumber200轮播容器高度
widthNumbernull轮播容器宽度,默认为容器父元素宽度
preArrowComponentReactNodenull自定义左箭头组件
nextArrowComponentReactNodenull自定义右箭头组件

swiper Event

namedescription
onChange轮播切换后触发事件,function(index: number){}
0.0.2

9 months ago

0.0.1

10 months ago