npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-scroll-react

v1.0.2

Published

React component for wrapping better-scroll library.

Downloads

155

Readme

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的使用更简单:

  1. 可以声明式的使用better-scroll
  2. 内部维护BetterScroll实例的创建和销毁;
  3. 内部自动创建滚动区域的wrapper,再也不用担心BetterScroll 初始化了, 但是没法滚动

安装

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)

属性

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

Issues

让我知道你的问题