• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Declarative in-view scroll monitor for React JS

react-inview-monitor

NPM version MIT License

Easy to use, declarative scroll into view component for animations and more

See the demos for some example usage.

There are other ~ scoll monitor libraries for React available, but none of them solved our use cases: to be able to declaratively configure animations and other effects to be triggered when individual elements came into the view. Inspired by the wow reveal animation library we set out to get to the same ease of use but within react's code paradigm.

Note: this library is not an overly generic, comprehensive, or low-level solution to managing scrolling. If you desire to solve one of the use cases we've had in mind it should be an ease for you to get running. If you need something that doesn't quite fit this solution, or if you just you need more control, consider one of the following libraries:

Usage

IntersectionObserver notes

This library uses IntersectionObserver under the hood.

Support

Until IntersectionObserver is supported in all modern browsers (see support tables) we recommend that you use it together with a polyfill, like the one from the following cdn which only polyfills (downloads code) if necessary: https://cdn.polyfill.io/v2/polyfill.js?features=IntersectionObserver

⚠️ This polyfill currently requires that you set html, body {height: 100%} in your css for it to function correctly.

What not to use this library for

IntersectionObserver uses requestIdleCallback internally, sacrificing low-latency (more direct) pixel accurate updates for performance. This means that there's not guarantee that the in/out of view updates will happen exactly when the element goes in/out of view - they can be delayed until the browser is less busy. For regular usage this is not a problem, but if you need a very high level of accuracy, this library (and IntersectionObserver) is not for you.

Reveal animation when scrolled into view

<InViewMonitor
  classNameNotInView='vis-hidden'
  classNameInView='animated fadeInUp'
>
  <ElementToAnimateIn />
</InViewMonitor>

Note: these classes are not included. We are big fans of animate.css for simple "just add water" animations.

Send custom prop to children when scrolled into view

Can be used for example to auto play a video. Toggle prop saves GPU and battery by stopping the video when no longer in view!

<InViewMonitor
  childPropsInView={{isPlaying: true}}
  toggleChildPropsOnInView={true}
>
  <VideoPlayer />
</InViewMonitor>

See these and more working examples on demo page.

Component properties

Property Type Description
classNameInView string common use: add classes to animate in element
classNameNotInView string common use: visually hide element to be animated in.
classNameAboveView string apply class when scrolled past view, f.e. sticky header.
classNameNotAboveView string apply class when not scrolled past view.
toggleClassNameOnInView boolean Toggle between classNameInView/classNameNotInView, instead of just replacing the first time element comes into view and then removing monitoring. default: false
childPropsInView object props propagated to the child element. Can be used to start video, complex animations and more.
childPropsNotInView object default: {}
toggleChildPropsOnInView boolean Toggle between childPropsInView/childPropsNotInView instead of just add childPropsInView the first time element comes into view and then removing monitoring.. default: false
onInView function callback when in view, can be used for tracking. Receives IntersectionObserverEntry as argument.
onNotInView function callback when not in view. Receives IntersectionObserverEntry as argument.
repeatOnInView boolean Repeats callbacks for onInView/onNotInView, rather than firing just the first time. default: false
intoViewMargin string - css margin Margin added to viewport for area to consider “in view”, can be negative. Use f.e. with positive value for lazy loading content just before in view, or with negative to start fading in element just after in view. Must be px or %. Default: ‘-20%’.
useInviewMonitor func Convenient function that can be used to dynamically disable the monitor, for example for mobile devices.
threshold number Value between 0 and 1 which indicate at what percentage of the target's visibility the observer's callback should be executed. default: 0

Contributing

Please see the Contribution Guidelines.

Copyright

This component is provided by Snips as Open Source Software. See LICENSE.txt for more information.

More Repositories

1

snips-nlu

Snips Python library to extract meaning from text
Python
3,889
star
2

Postal

A Swift framework for working with emails
Swift
653
star
3

snips-nlu-rs

Snips NLU rust implementation
Rust
340
star
4

ntm-lasagne

Neural Turing Machines library in Theano with Lasagne
Python
300
star
5

awesome-snips

A curated list of awesome Snips projects
276
star
6

tensorflow-build

A set of scripts to (cross-)build the Tensorflow C lib for various architectures / OS
Shell
178
star
7

rust-threshold-secret-sharing

A pure-Rust implementation of various threshold secret sharing schemes
Rust
156
star
8

rust-paillier

A pure-Rust implementation of the Paillier encryption scheme
Rust
80
star
9

snips-nlu-ontology

Ontology of Snips NLU
Rust
57
star
10

react-scrolling-color-background

background with color transitioning as you scroll, declarative and easy to setup
JavaScript
57
star
11

sda

Secure distributed aggregation of high-dimensional vectors
Rust
55
star
12

snips-skill-respeaker

Official Snips Animation Feedback For Makers Kits/Dev Kits, supporting all kinds of APA102 based LED hardwares.
C
41
star
13

snips-record-personal-hotword

Python
40
star
14

hermes-protocol

Definition of the Hermes protocol used by the Snips platform
Rust
36
star
15

snips-nlu-language-resources

Language resources for the Snips Natural Language Understanding (NLU)
Python
34
star
16

snips-platform-android-demo

A demo of the Snips Platform for Android
Java
22
star
17

paillier-libraries-benchmarks

Companion repository for blog post on benchmarking implementations of Paillier encryption
Go
19
star
18

SuperCombinators

[Deprecated] A Swift parser combinator framework
Swift
19
star
19

nlp-workshops

Introduction and tutorial about Natural Language Processing
Jupyter Notebook
16
star
20

snipsmanager

The Snips Assistant Manager
Python
16
star
21

snips-nlu-parsers

Rust crate for entity parsing
Rust
16
star
22

gazetteer-entity-parser

Rust library for parsing and resolving entity values based on a gazetteer
Rust
16
star
23

snips-issues

Feel free to share your bugs with us.
14
star
24

snips-app-sonos

Sonos app for Snips
Python
13
star
25

snips-nlu-metrics

Python package to compute metrics on an NLU intent parsing pipeline
Python
13
star
26

snips-nlu-utils

Rust library for NLU utils with wrappers in other languages
Rust
12
star
27

snips-app-template-py

Action code template written in Python.
Python
11
star
28

snips-platform-swift

The Swift framework for the Snips Platform
Swift
11
star
29

snips-actions-templates

Template files for snips actions
Python
11
star
30

snips-nlu-resources

10
star
31

play-mongo-bson

Scala client for MongoDB using macros for case class serialization/deserialization
Scala
10
star
32

snips-platform-docker

Shell
10
star
33

snips-skill-owm

OpenWeatherMap skill for Snips
Python
9
star
34

snips-javascript-toolkit

Everything you need in order to write Snips actions in javascript / typescript.
TypeScript
9
star
35

snips-skill-hue

Philips Hue skill for Snips
Python
8
star
36

create-snips-action

Generator for writing Snips action code in Javascript/Typescript.
JavaScript
7
star
37

crfsuite-rs

Rust bindings for CRFSuite
C
7
star
38

snips-jeedom-plugin

Jeedom plugin allows connecting Snips voice assistant with Jeedom platform.
PHP
6
star
39

snips-demo-dev-kit

Official action code for Snips Voice Interaction Development Kit. (Temperature & Relay)
Python
6
star
40

snips-javascript-actions-runner

A lightweight javascript actions runner. 🏃‍♂️
JavaScript
5
star
41

ripb

A rust crate providing an implementation of a lock-free type-safe in-process bus.
Rust
4
star
42

snips-action-alarm

Snips action code for the Alarm app
TypeScript
4
star
43

snipsmanagercore

Core Python utilities for the Snips Manager
Python
4
star
44

snips-skill-fakeweather

Fake weather forecasts for Snips
Python
3
star
45

snips-app-relay-switch

Control the switch connected on Raspberry Pi by using your voice.
Python
3
star
46

snips-skill-weather

skill for the Snips assistant, En & Fr
JavaScript
2
star
47

snips-skill-weather-tts

Skill to show how to parse a weather intent and respond with a TTS.
Python
2
star
48

snips-skill-neopixel

NeoPixel Ring 24 skill for Snips
Python
2
star
49

snips-app-sht31

Get temperature and humidity from SHT31 (I2C protocol) by using your voice.
Python
2
star
50

snips-actions-runner-hook

Temporary solution to link snips-skill-server and snips-actions-runner
JavaScript
1
star
51

braccio_arm_demo

Code to control the braccio robotic arm for maker fare
Python
1
star
52

snips-action-reminder

Snips action code for the Reminder app
TypeScript
1
star
53

snips-action-timer

Snips action code for the Timer app
TypeScript
1
star
54

snips-action-unit-converter

Snips action code for the Unit Converter app
TypeScript
1
star
55

snips-action-nutrition

Snips action code for the Nutrition app
TypeScript
1
star
56

homebrew-snips

Snips formulae for the Homebrew package manager
Ruby
1
star
57

snipsair_whitepaper

Snips whitepapers, summaries, traductions etc.. Get in touch if you would like to help translate!
1
star
58

snips-skill-hue-pro

Handler for [Smart Light - Hue] bundle.
Python
1
star
59

SDP-swift

Swift reference implementation for Simple Datagram Protocol.
Swift
1
star
60

create-snips-action-typescript

Generator for writing Snips action code in Typescript.
TypeScript
1
star
61

Snips_Lights

Arduino library for light animations for the smart speaker project.
C++
1
star
62

snips-skill-times-tables-quiz

This skill enable your snips voice assistant to give you a quiz on times tables under the form of a dialog session.
Python
1
star