npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reading-position-indicator

v2.0.3

Published

Reading position indicator on a webpage

Downloads

3,293

Readme

reading position indicator

Small mobile friendly reading position indicator library with no external dependencies.

demo

  • https://codepen.io/kunukn/full/zNJqEE (version 1.0.3+)
  • https://codepen.io/kunukn/full/ayeMZN/ (version 2.0.0+)

about

A position indicator at the top of the page to visually display how far you have scrolled on a webpage.

Build with focus on simplicity, performance and a11y. Using transform translate for best performance. rAF for throttling scroll update and debounce for resize update.

Aria tags are used to support screen readers.

The progress element <progress> has not been used because the code gets messy with vendor prefixes and removing the default styles that comes with each browser. It gets even messier when fallback elements are added inside the progress element to support older browsers.

browser support

IE | Chrome | Firefox | Opera | Safari --- | --- | --- | --- | --- | IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |

npm

https://www.npmjs.com/package/reading-position-indicator

size

  • js ~6kb
  • css <1kb

test

Tested with latest Chrome, Safari, Firefox, Edge, IE10+, iOS7+, Android 4.3+

usage

Check the dist/index.html for inspiration.

  • Add reference to rpi.bundle.js and rpi.bundle.css in the html page
  • Apply the markup structure
  • Init the library with JS

html structure

<head>
  ...
  <link rel="stylesheet" href="rpi.bundle.css">
  ...
</head>
<body>
  <!-- library markup -->
  <div class="rpi-progress-bar" 
    role="progressbar" 
    aria-valuemin="0" 
    aria-valuemax="100"
    aria-valuenow="0">
      <div class="rpi-progress-bar__position" aria-hidden="true"></div>
      <div class="rpi-progress-bar__percentage"></div>
  </div>
  <!-- end library markup -->
  
       ...          
       
       <script src="rpi.bundle.js"></script> <!-- library -->
       <script>new ReadingPositionIndicator().init();</script> <!-- usage -->
 </body>

minimum markup required

<div class="rpi-progress-bar">
      <div class="rpi-progress-bar__position"></div>
      <div class="rpi-progress-bar__percentage"></div>
</div>

configuration and usage example

var rpi;
setTimeout(function waitUntilDomIsReadyLoadingCustomFontsMightOffsetThis() {
  rpi = new ReadingPositionIndicator({
    rpiArea: '[data-rpi-area]', /* optional, query selector to an element */
    progressBar: { /* optional */
      show: true, /* default true */
      color: 'rgba(0, 120, 120, .5)', /* default from css */
    },
    percentage: { /* optional */
      show: true, /* default false */
      displayBeforeScroll: false, /* default false */
      opacity: .3, /* default from css */
      color: '#000', /* default from css */
    },
  }).init();
}, 200); // wait until DOM has fully rendered the article to get the calculations correct
// rpi.destroy(); // use when to be removed
// rpi.update(); // optional force update, example: DOM was updated and need to refresh the indicator

development

  • git clone the project or download it
  • npm install
  • npm start
  • open a browser and go to localhost:3333

build library into dist folder

  • npm run build

how does it work?

It calculate heights for viewport, document and current scroll position. If rpiArea is used then it also uses getBoundingClientRect method to calculate dom element dimension. DOM updates are only applied if data has changed since last time. The calculation is updated on scroll and resize event and the information is updated to the DOM.

license

MIT License: http://opensource.org/licenses/MIT