Socket
Socket
Sign inDemoInstall

scroll-percentage

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-percentage

get scrolled percentage of a scrollable element


Version published
Weekly downloads
289
increased by24.03%
Maintainers
1
Weekly downloads
 
Created
Source
yarn add scroll-percentage
import { calculateScrollPercentage } from 'scroll-percentage'

Or attach this script in your html.

<script src="https://unpkg.com/scroll-percentage@1.0.7/dist/index.js"></script>
document.querySelector('.parent-elem').addEventListener('scroll',e => {
  let scrollPercentage = calculateScrollPercentage(e.target)
  console.log('scroll percentage', scrollPercentage)
})
// If the parent/scrolling element is `window`, 
// then provide a second parameter - height of the child element.
// Which is basically - the element `window` is scrolling by -
let childElemHeight = document.querySelector('.child-elem').clientHeight

window.addEventListener('scroll', e => {
  let scrollPercentage = calculateScrollPercentage(e.target, childElemHeight)
  console.log('scroll percentage', scrollPercentage)
})

N.B: While calculating the height of child elemenet, adjust the value with margin/padding size.

FAQs

Package last updated on 02 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc