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

circle-slider

v3.0.4

Published

A slider, except it's round

Downloads

168

Readme

circle-slider

A slider, except it's round. Pretty good for selecting angles and stuff.

Demo here.

Install

$ npm i circle-slider

Usage

Basic usage:

HTML:

<div id="whatever"></div>

JS:

// Import the module at the top of your file
const CircleSlider = require("circle-slider");

// or ES6 style
import CircleSlider from "circle-slider";

// The id of your target element as the first arg
const cs = new CircleSlider("whatever");

All you have to do on the HTML side is to create a div with some id, which is the first parameter in the constructor of CircleSlider.

All you need is to create a div, the elements for the handle (and its container) will be created for you.

You can put anything you want inside the div, e.g. a div which displays the current angle (see the demo).

Options

The constructor takes an optional second parameter which looks like this:

{
  // e.g. snap to every 45 degrees
  snap: Number,

  // positive direction
  clockwise: Boolean,

  // which position 0 degrees is
  startPos: "top"|"bottom"|"left"|"right",
}

I'll emphasize that startPos changes where 0 degrees is, so if you instead want, for example, 0 to be at the top, but want the slider to start at 90 degrees, you should call setAngle(90) (see below) after creating the slider.

Example usage:

const options = {
  snap: 45,
  clockwise: false,
  startPos: "top",
};
const cs = new CircleSlider("id", options);

You can also write the first parameter with a #:

new CircleSlider("#id");

With or without #, there is no difference in functionality, so choose which one you prefer.

Methods

Here is the stuff you can do with CircleSlider:

// get the current angle value
cs.getAngle();

// set the angle manually
cs.setAngle(45);

// fires every time the slider is moved
// the emitted event will give you the angle
cs.on("sliderMove", (angle) => {
    someDiv.textContent = angle;
})

// fires every time the handle stops moving
// can be useful to avoid heavy operations every time the
// handle moves
cs.on("sliderUp", (angle) => {
    someDiv.textContent = angle;
})

Note that the sliderMove event gets triggered when using setAngle.

Since CircleSlider extends eventemitter3, you can also use functions like once instead of on.

Further reading here (eventemitter3 uses the same API as node events).

Styling

I leave most styling up to you! However, there are some CSS rules that you must use in order for the handle two rotate properly and stuff. Here are some good defaults to get started with:

#slider {
  /*
    position: relative is needed for the handle to be
    positioned correctly, and border-radius: 100% just
    makes the div round.
  */
  position: relative;
  border-radius: 100%;

  /* Other than the above two, go wild! */
  height: 300px;
  width: 300px;
  background: linear-gradient(90deg, #FF9A9E, #FAD0C4);
}

/*
  Probably best to paste this exactly as is.
  These CSS rules make sure that the handle rotates
  properly, so don't change anything here.
*/
.cs-handle-container {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
}

/* Also paste as is */
.cs-handle {
  position: absolute;
  transform: translateY(-50%);
}

/* the appearance of the handle, feel free to change! */
#slider .cs-handle {
  height: 30px;
  width: 30px;
  /*
    Change 'right' to change the offset from the edge.
    E.g right: 0 puts the handle just next to the edge
    of #slider, on the inside
  */
  right: -15px;
  cursor: default;
  border-radius: 100%;
  background: linear-gradient(180deg, #FFFFFF, #efefef);
  box-shadow: rgba(0, 0, 0, 0.3) 0 1px 10px 0;
}

#slider .cs-handle:active {
  background: linear-gradient(180deg, #EBEBEB, #DFDFDF)
}