Socket
Book a DemoInstallSign in
Socket

reading-position-indicator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reading-position-indicator

Reading position indicator on a webpage

1.0.0
Source
npmnpm
Version published
Weekly downloads
112
8.74%
Maintainers
1
Weekly downloads
 
Created
Source

reading position indicator

Small mobile friendly reading position indicator library with no dependencies.

demo

http://codepen.io/kunukn/full/zNJqEE

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

IEChromeFirefoxOperaSafari
IE 10+ ✔Latest ✔Latest ✔Latest ✔Latest ✔

size

  • js ~5kb
  • 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 id="rpi-progress-bar-container" 
    class="rpi-progress-bar-container" 
    role="progressbar" 
    aria-valuemin="0" 
    aria-valuemax="100"
    aria-valuenow="0">
      <div class="rpi-progress-bar-container__position" aria-hidden="true"></div>
      <div class="rpi-progress-bar-container__percentage"></div>
  </div>
  <!-- end library markup -->
  
       ...          
       
       <script src="rpi.bundle.js"></script> <!-- library -->
       <script>new ReadingPositionIndicator().init();</script> <!-- usage -->
 </body>

minimum markup required

<div id="rpi-progress-bar-container" class="rpi-progress-bar-container">
      <div class="rpi-progress-bar-container__position"></div>
      <div class="rpi-progress-bar-container__percentage"></div>
</div>

configuration example

var rpi = new ReadingPositionIndicator({
          color: 'navyblue', // progress bar color
          percentage: {
            show: true,
            opacity: .3,
            color: '#000',
          },
        }).init();
//rpi.destroy(); // use when to be removed

how does it work?

It uses JS to calculate the document height and the viewport height to calculate the current position. The calculation is updated on scroll and resize event and the information is updated to the markup.

license

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

FAQs

Package last updated on 10 Feb 2017

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.