Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swissup/range-slider

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swissup/range-slider

Tiny html range slider with two thumbs

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

RangeSlider

Tiny html range slider with two thumbs. 1.5kB of minified and gzipped JS and CSS.

View Demo

Installation

Download source files and add them to the page:

<head>
    <script src="range-slider.js" defer></script>
    <link href="range-slider.css" rel="stylesheet">
</head>

Minified versions:

Usage

Add the following html to use a range slider:

<range-slider name="price" min="0" max="100" value="10-90" step="10"/>

Of course, you can work with the component in javascript:

const range = document.querySelector('range-slider');

range.value = [30, 40];

document.addEventListener('range:input', function (event) {
    console.log(event.target.value);
});

Prevent CLS

To prevent layout shift when slider is initializing use the following html instead of short one:

<range-slider name="price" min="0" max="100" value="10-90" step="10">
    <input class="range" type="range" min="0" max="100" value="10" step="10"/>
    <input class="range" type="range" min="0" max="100" value="90" step="10"/>
    <input class="filler" disabled type="range"/>
</range-slider>

Styles

You can style the component with CSS and CSS variables.

VariableDefault Value
--thumb-width16px
--thumb-heightvar(--thumb-width)
--thumb-mobile-scale1.4
--thumb-mobile-widthcalc(var(--thumb-width) * var(--thumb-mobile-scale))
--thumb-mobile-heightcalc(var(--thumb-height) * var(--thumb-mobile-scale))
--thumb-border1px solid #fff
--thumb-border-radius999px
--thumb-bg10 89 254
--thumb-mobile-scale1.4
--track-height4px
--track-border-radiusvar(--thumb-border-radius)
--track-bg234 234 234

Check out the Demo Page for more examples.

Credits

The idea belongs to the unknown StackOverflow user.

Keywords

FAQs

Package last updated on 13 Sep 2024

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