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

mor-scroll-watcher

v0.5.3

Published

Mona系列 - React滚动监听组件

Downloads

25

Readme

Mona系列 - React滚动监听组件

✨✨ 这是一款非常有用轻巧的 React 组件,你可以应用到任何需要滚动监听的场景

npm npm

点我看一下效果

使用场景

  • 滚动曝光埋点
  • 图片懒加载
  • 视图区域按需加载

...

依赖

使用指南

import Watcher from 'mor-scroll-watcher'
const WatcherItem = Watcher.item

Watcher.init(options)
<WatcherItem ...>
	...
</WatcherItem>

你只需要将需要被滚动触发的节点设置为WatcherItem节点的children,就能达到滚动触发的目的。

代码演示

import React, { Component } from 'react'
import Watcher from 'mor-scroll-watcher'

const WatcherItem = Watcher.item

export default class Home extends Component {
	componentDidMount () {
		new Watcher({
			wrap: findDOMNode(this.refs.views)
			// bottomEmit: 100,
			// initEmit: false
		})
	}

	onWatcher (index) {
		// do something
		console.log(index)
	}

	render () {
		const list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
		return (
			<div className="wrap" ref="views">
				<For of={list} each="item" index="index">
					<WatcherItem
						className="w-full scroller-item"
						key={index}
						style={{
							height: '200px',
							background: 'yellow',
							margin: '20px 0'
						}}
						onWatcher={this.onWatcher.bind(this, index)}
					>
						{item}
					</WatcherItem>
				</For>
			</div>
		)
	}
}

高阶用法

当页面内存在多个需要被监听滚动的容器时,需要设置唯一ID

import React, { Component } from 'react'
import Watcher from 'mor-scroll-watcher'

const WatcherItem = Watcher.item

export default class Home extends Component {
	componentDidMount () {
		new Watcher({
			wrap: findDOMNode(this.refs.views)
			monaId: 'weiyiID_123456'
			// bottomEmit: 100,
			// initEmit: false
		})
	}

	onWatcher (index) {
		// do something
		console.log(index)
	}

	render () {
		const list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
		return (
			<div className="wrap" ref="views">
				<For of={list} each="item" index="index">
					<WatcherItem
						monaId: 'weiyiID_123456'
						className="w-full scroller-item"
						key={index}
						style={{
							height: '200px',
							background: 'yellow',
							margin: '20px 0'
						}}
						onWatcher={this.onWatcher.bind(this, index)}
					>
						{item}
					</WatcherItem>
				</For>
			</div>
		)
	}
}

options

| 参数 | 说明 | 类型 | 默认值 | 是否必传 | | --- | --- | --- | --- | :-- | | wrap | 滚动容器 | DOM原生节点 | - | yes | | monaId | 当页面内存在多个需要监听的容器时,需要设置唯一的id,并与被监听的WatcherItem的属性monaId保持统一 | String | - | - | | bottomEmit | 滚动距离底部的触发距离 | Number | 0 | no | | initEmit | 初始化是否需要触发一次 | Boolean | true | no |

WatcherItem

| 参数 | 说明 | 类型 | 默认值 | 可选项 | | --- | --- | --- | --- | :-- | | onWatcher | 触发之后的回调 | Function | - | - | | monaId | 当页面内存在多个需要监听的容器时,需要设置唯一的id,并与初始化的实例的属性monaId保持统一 | String | - | - | | className | className属性 | String | - | - |

联系我

微信:599321378