New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

position-indicator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

position-indicator

position indicator library

latest
Source
npmnpm
Version
0.0.12
Version published
Maintainers
1
Created
Source

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

Codesandbox ReactViewEdit
Codesandbox VueViewEdit
Codesandbox AngularViewEdit
Codepen VueViewEdit

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.

Keywords

typescript

FAQs

Package last updated on 17 May 2021

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