Socket
Book a DemoInstallSign in
Socket

better-scroll-react

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-scroll-react

React component for wrapping better-scroll library.

1.0.2
latest
npmnpm
Version published
Weekly downloads
14
180%
Maintainers
1
Weekly downloads
 
Created
Source

better-scroll-react

better-scroll的使用更简单。

import BetterScroll from 'better-scroll-react'

function Index() {
	return (
		<>
			<div style={{height: 400, border: '1px solid'}}>
				<BetterScroll>
					<div style={{
						height: 600,
						background: 'red'
					}}>
						Hello better-scroll-react
					</div>
				</BetterScroll>
			</div>
		</>
	)
}

注意better-scroll-react不是better-scroll的React实现,只是在better-scroll基础上包装了一层,让better-scroll的使用更简单:

安装

npm install @better-scroll/core better-scroll-react

使用

import BetterScroll from 'better-scroll-react'

function Index() {
	return (
		<>
			<div style={{height: 400, border: '1px solid'}}>
				<BetterScroll>
					<div style={{
						height: 600,
						background: 'red'
					}}>
						Hello better-scroll-react
					</div>
				</BetterScroll>
			</div>
		</>
	)
}

better-scroll-react组件的属性以及属性默认值逻辑同better-scroll 配置项

获取BetterScroll实例

通过ref可以获取BetterScroll实例

import BetterScroll from 'better-scroll-react'
import { useEffect, useRef } from 'react'


function Index() {
	const scrollRef = useRef();
	useEffect(() => {
		scrollRef.current.on('scrollStart', () => {
			console.log('Begin scroll')
		})
	}, [])

	return (
		<>
			<div style={{height: 400, border: '1px solid'}}>
				<BetterScroll ref={scrollRef}>
					<div style={{
						height: 600,
						background: 'red'
					}}>
						Hello better-scroll-react
					</div>
				</BetterScroll>
			</div>
		</>
	)
}

插件使用

插件使用方式同better-scroll

import BetterScroll from 'better-scroll-react'
import Pullup from '@better-scroll/pull-up'
import { useEffect, useRef } from 'react'

const plugins= [
    // 插件和插件配置
	[Pullup, { pullUpLoad: true }]
]

function Index() {
	const scrollRef = useRef();

	useEffect(() => {
		scrollRef.current.on('pullingUp', () => {
			console.log('pullingUp')
			setTimeout(() => {
				scrollRef.current.finishPullUp()
			}, 1000)
		})
	}, [])

	return (
		<>
			<div style={{height: 400, border: '1px solid'}}>
				<BetterScroll ref={scrollRef} plugins={plugins}>
					<div style={{
						height: 600,
						background: 'red'
					}}>
						Hello better-scroll-react
					</div>
				</BetterScroll>
			</div>
		</>
	)
}

插件的配置属性不能直接传给better-scroll-react组件,必须在plugins属性里传递(如上面DEMO)

属性

名称类型默认值描述
addContentNodebooleantrue是否给滚动内容包裹个div节点,处理多子节点的场景
classNamestringwrapper容器className
styleObjectwrapper容器style
pluginsArray<>BetterScroll插件,传入格式:{plugins: [PullDown]}, 插件配置数据传入:{ plugins:[[PullDown, {pullDownRefresh: true}]] }
其他属性同BetterScroll 2.0 Options

Issues

让我知道你的问题

Keywords

better-scroll

FAQs

Package last updated on 29 Sep 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.