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

rangetouch

v2.0.1

Published

A super tiny library to make input type='range' sliders work better on touch devices

Downloads

461,819

Readme

RangeTouch

A super tiny library to make <input type="range"> sliders work better on touch devices.

Donate - Demo - npm version

Why bother?

While building the Plyr media player I noticed how bad the experience was trying to use <input type="range"> is on a touch device (particularly iOS). Touching the track on a desktop will jump the thumb handle to that point. However on some touch devices this simply focuses the input and to adjust the value you need to touch and drag the handle. This is something that I can't help but feel will eventually be fixed by the browser vendors but for now, you can use RangeTouch to fill that gap.

Features

  • ~1KB minified and gzipped
  • No dependencies (written in "vanilla" JavaScript)
  • Uses event delgation so no need to re-run after DOM manipulation

Quick setup

1. Include the lib

Either use the ES6 module:

import RangeTouch from 'rangetouch';

...or include the script:

<script src="https://rangetouch.com/2.0.1/rangetouch.js"></script>

2. Create instance(s)

Single instance

const range = new RangeTouch('input[type="range"]', { ...options });

The first argument can either be:

The second argument is for options.

This will return a reference to the single instance.

Multiple instances

To setup multiple inputs at one time, you can use the following static method:

const ranges = RangeTouch.setup('input[type="range"]', { ...options });

The first argument can either be:

The second argument is for options.

This will return an array of RangeTouch instances that it setup.

Options

| Property | Type | Default | Description | | ---------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | addCSS | Boolean | true | Whether to inject CSS to improve the usability of the inputs. It's recommended you add this yourself if you don't want RangeTouch to take care of it. | | thumbWidth | Integer | 15 | This value is used as part of the calculation to determine the value the users selects when touching the range track. Unfortunately as JavaScript can't access the shadow DOM, this value can't be automatically determined. I would recommend customisation (and setting the size of the thumb) given all OS and browser combinations seem to render the control differently. | | watch | Boolean | true | Watch for new elements added to the DOM that match your string selector. Note: This only applies when using the multiple instance RangeTouch setup method and also requires a string selector as the first argument. |

API

| Method | Arguments | Description | | --------- | --------- | -------------------------------------------------------- | | destroy() | N/A | Destroy the current instance and remove event listeners. |

To call an API method, you need a reference to the instance. For example:

const range = new RangeTouch('input[type="range"]', { ...options });
range.destroy();

Issues

If you find anything weird with RangeTouch, please let us know using the GitHub issues tracker and be descriptive on how to reproduce, expected result, the browser (and version) used, etc.

Author

RangeTouch is developed by @sam_potts / sampotts.me

Donate

RangeTouch costs money to run for domains, hosting and more. Any help is appreciated... Donate to support RangeTouch

Thanks

Fastly

Thanks to Fastly for providing the CDN services.

Copyright and License

The MIT license.