Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

pc-swiper

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pc-swiper

preact swiper flow control by rxjs

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

pc-swiper

https://travis-ci.com/deepkolos/pc-swiper

一个使用rxjs做交互流程管理的swiper, 适用于preact项目, hooks编写, 有如下特性

  • 横向/纵向滚动
  • tab页面懒初始化
  • 溢出动画
  • 支持嵌套([横|纵]嵌[横|纵])+
  • 体积相对较小(压缩后26.6k, swiper.min.js则有124.9k)

Live Demo

Link

demo

Props

参数类型默认值描述
indexnumber0默认参数
poolnumber3初始化距离当前tab范围
thresholdnumber0.13滑动到下一页阈值
directionDirectionDirection.horizontal方向
swipeableRangeArray[0, children.length - 1]可滚动范围, 用于条件滚动
overflowbooleanfalse溢出回弹
maxOverflownumber25最大可以出px
flingDurationnumber800手指离开屏幕后动画时长
flingEaseFnFunctioneaseOutQuintfling缓动函数
classNamestringswiper根元素className

建议一下props更新通过拿ref更新, 比如: swiperRef.current.swipeableRange = [0, 1]

Events

事件名参数描述
onProgressProgressInfo有位移/进度变化时触发
onSwipeEndInfo当手指离开屏幕触发
onFlingEndInfo当惯性滚动结束后触发
onOverflowOverflowInfo当手指离开屏幕且触发溢出时触发, 前置条件overflow: true

Event Params: ProgressInfo

参数类型描述
tabnumber当前tab
percentnumber距离目标tab百分比

Event Params: Info

参数类型描述
tabnumber当前tab

Event Params: OverflowInfo

参数类型描述
overflowEdgeDirection溢出方向

VM Public Methods

方法参数描述
gotoindex(number)跳转到目标tab

Demo Code

function Page() {
  return <div>
    <Swiper>
      <SwiperItem>1</SwiperItem>
      <SwiperItem>2</SwiperItem>
      <SwiperItem>3</SwiperItem>
    </Swiper>
  </div>
}

TODO

  • 滑动增益(win8.1 应用菜单所应用肉眼减少触控延迟的方法, 提高跟手感觉)
  • 横向滚动高度自适应(TBD, 可以通过onSwipe API可以实现, 只是一些初始化样式数据需要自己维护)
  • 溢出加载更多
  • 支持循环
  • 支持多页滑动, 而非仅仅单页
  • 溢出回弹可自定义
  • 支持PC

License

MIT 造轮子锻炼抽象能力

FAQs

Package last updated on 07 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts