0.0.12 • Published 3 years ago

position-indicator v0.0.12

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

Position Indicator

npm version npm downloads License Library minified size Library minified + gzipped size

About

Minimal VanillaJS code to know the scroll position of the page with no external dependencies.

A position indicator that updates on:

  • scroll
  • resize
  • body height change.

It has been tested on

  • Phones (iOS, Android)
  • Tablets (iPadOS, Android)
  • Laptops (Mac, Windows)
  • Modern browsers

It updates when the devices rotates and if the height changes on interaction.

Browser Support

ChromeSafariFirefox
60+12+60+

Demo

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

yarn add position-indicator

# For npm, use the command below.
npm install position-indicator --save

Usage

import { createPositionIndicator } from 'position-indicator'

let myOnInitCallback = (data) => {}
let myOnUpdateCallback = (data) => {}

// where data is:
let data = {
  position /* value between 0 and 1 */,
  prevPosition /* value between 0 and 1 */,
  hasUpdated /* if position is different from previous event */,
  hasScroll /* true or false */,
  eventType /* scroll, resize, heightChange or init */,
  eventDate /* Date.now() */,
}

let positionIndicator = createPositionIndicator({
  onInit: myOnInitCallback,
  onUpdate: myOnUpdateCallback,
  useResizeListener: true, // optional: default true
  useResizeObserver: true, // optional: default true
})

positionIndicator.init()

// Then later when not used anymore
positionIndicator.destroy()

Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/position-indicator"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/position-indicator"></script>

<script>
  // UMD module is exposed through the "positionIndicator" global variable.
  console.log(positionIndicator)
</script>

Explore the dist files

https://unpkg.com/position-indicator/

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago