Socket
Socket
Sign inDemoInstall

scroll-percentage

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    scroll-percentage

get scrolled percentage of a scrollable element


Version published
Weekly downloads
303
increased by8.6%
Maintainers
1
Install size
2.10 kB
Created
Weekly downloads
 

Readme

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.9/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

Last updated on 02 Jun 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc