1.0.0 • Published 2 years ago

rc-seamless-scroll v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

🏠 主页地址

React Component based on requestAnimationFrame API for transportation element.

安装

yarn add rc-seamless-scroll

# or

npm i rc-seamless-scroll

快速上手

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import ReactSeamlessScroll, { SeamlessScrollInctance } from 'rc-seamless-scroll';

const listData = [
  {
    title: '无缝滚动组件展示数据第1条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第2条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第3条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第4条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第5条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第6条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第7条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第8条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第9条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第10条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第11条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第12条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第13条',
    date: Date.now(),
  },
  {
    title: '无缝滚动组件展示数据第14条',
    date: Date.now(),
  },
];
const App = () => {
  const ref = React.useRef < SeamlessScrollInctance > null;
  return (
    <ReactSeamlessScroll list={listData} ref={ref}>
      {listData.map((item, index) => (
        <div key={index} style={{ height: 22 }}>
          <span style={{ marginRight: 22 }}>{item.title}</span>
          <span>{item.date}</span>
        </div>
      ))}
    </ReactSeamlessScroll>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));

SeamlessScrollInstance

  • onReset 重置滚动
  • onStopMove 停止滚动
  • onStartMove 开始滚动

Props

属性描述类型是否必需默认值
isAutoScroll是否开启自动滚动booleantrue
list原始数据列表Record<string, any>[]-
ref引用组件方法SeamlessScrollInstance-
step步进速度,step 也是单步大小的约数number1
limitScrollNum开启滚动的数据大小number3
hover是否开启鼠标悬停booleanfalse
direction控制滚动方向up , down , left , right'up'
singleHeight单步运动停止的高度(每一项的高度)number-
singleWidth单步运动停止的宽度(每一项的宽度)number-
singleWaitTime单步停止等待时间number1000ms
isRemUnit是否开启 rem 单位booleanfalse
delay动画延迟时间number0ms
ease动画方式(与 css 过度效果配置一致)string或者{x1:number,x2:number,y1:number,y2:number}ease-in
count动画循环次数,默认-1 表示一直动画 0 表示不循环number-1
copyNum拷贝几份滚动列表number1
wheel开启鼠标悬停时支持滚轮滚动(hover 为 true 时生效)booleanfalse
wrapperClassName最外层盒子类名string-
wrapperHeight最外层盒子高度numberchildren 列表的高度
children列表节点ReactNode-

注意 : singleHeight/singleWidth设置的值必须和 item 每一项的高度(宽度)值一样 , 否则可能会引起单步滚动不准!

参与贡献

git clone https://github.com/llq0802/rc-seamless-scroll.git
#or
git clone git@github.com:llq0802/rc-seamless-scroll.git

cd rc-seamless-scroll
yarn
yarn start

打开一个新的终端

cd example
yarn
yarn start
访问`http://localhost:1234`

测试

yarn test

联系我

👤 VX : llq958614130 | E-mail : 958614130@qq.com

支持

❤️ ❤️ ❤️ 觉得还行的话请不吝啬你的小心心奥 ❤️ ❤️ ❤️


This README was generated with ❤️ by readme-md-generator