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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lf2com/knob.js

v2.0.1

Published

Knob.js is a DOM for spinning and getting the degree

Downloads

3

Readme

knob.js

Knob.js is a HTML element for spinning and getting the degree.


Demo

Knob

Sets knob with min, max, and degree. Also we can change the size of knob.

CD

An application of knob with CD styled media player.

Get Started

<script defer src="https://unpkg.com/@lf2com/knob.js@latest/dist/knob.min.js"></script>
<!-- or -->
<script defer src="https://cdn.jsdelivr.net/gh/lf2com/knob.js@latest/dist/knob.min.js"></script>

Use knob in HTML:

<knob-line min="-30" max="120"></knob-line>

Or in JavaScript code:

const knob = document.createElement('knob-line');

knob.setAttribute('min', -30);
knob.setAttribute('max', 120);
// or
knob.min = -30;
knob.max = 120;

document.body.append(knob);

As knob.js is an element, we can code in jQuery:

$('<knob-line>')
  .attr({
    min: -30,
    max: 120,
  })
  .appendTo($('body'));

Or in React:

const Knob = () => (
  <knob-line min="-30" max="120" />
);

Styled Knobs

There are default styled knobs we can use directly without styling knob ourselves.

Dot Knob

Dot knob

<knob-dot></knob-dot>

Line Knob

Line knob

<knob-line></knob-line>

Triangle Knob

Triangle knob

<knob-triangle></knob-triangle>

Customize Knob

We can customize knob with knob base element:

Custom knob

:warning: When customizing knob we need to append child node to <knob-base> and style the child node.

<style>
  knob-base > .knob {
    width: 100px;
    height: 80px;
    box-shadow: 0 0 5px #999;
    box-sizing: border-box;
    border-radius: 20%;
    border: 3px solid #ccc;
    display: inline-block;

    /* ensure the knob can receive mouse/touch event */
    background-color: rgba(0, 0, 0, 0);
  }
</style>

<body>
  <knob-base>
    <!-- knob doesn't rotates itself but its children -->
    <span class="knob"></span>
  </knob-base>
</body>

Build

Build flip.js with the command:

npm run build

And get the built file at ./dist/knob.min.js.

Properties

Properties for setting knob.

.disabled

Type of value: boolean

Set true to disallow spinning the knob.

<!-- disable knob -->
<knob-line disabled></knob-line>
// disable knob
knob.disabled = true;
// or
knob.setAttribute('disabled', '');

// check if knob is disabled
if (knob.disabled) {
  console.log('Knob is disabled');
}

.degree

Type of value: number

Default: 0 or the bound value within .min and .max.

Degree of knob.

<!-- set degree -->
<knob-dot degree="30"></knob-dot>
// set degree
knob.degree = 30;
// or
knob.setAttribute('degree', 30);

// get degree in number
console.log('degree:', knob.degree);
// or in string
console.log('degree:', knob.getAttribute('degree'));

.value

Alias of .degree.

// set value
knob.value = 30;

// get value
console.log('value:', knob.value);

.min

Type of value: number

Default value: -Infinity

Minimum degree of knob.

<!-- set min/max -->
<knob-triangle min="-60"></knob-triangle>
// set min
knob.min = -60;
// or
knob.setAttribute('min', -60);

// get min in number
console.log('min:', knob.min);
// or in string
console.log('min:', knob.getAttribute('min'));

.max

Type of value: number

Default value: Infinity

Maximum degree of knob.

<!-- set min/max -->
<knob-triangle max="150"></knob-triangle>
// set max
knob.max = 150;
// or
knob.setAttribute('max', 150);

// get max in number
console.log('max:', knob.max);
// or in string
console.log('max:', knob.getAttribute('max'));

Events

Events for knob elements:

change

Cancelable: false

Dispatches on change of knob degree.

Values of event.detail:

| Name | Type | Description | | -: | :-: | :- | | degree | number | Current degree | | lastDegree | number | Degree before changing | | offsetDegree | number | Difference degree from lastDegree to degree |

spinstart

Cancelable: true

Would not able to spin the knob if the event is canceled.

Dispatched on start of spinning.

Values of event.detail:

| Name | Type | Description | | -: | :-: | :- | | degree | number | Current degree | | lastDegree | number | Degree of beginning. Should be the same as degree | | offsetDegree | number | Difference degree from lastDegree to degree. Should be 0 |

spinning

Cancelable: true

Would temporarily keep the knob from spinning if the event is canceled.

Dispatches on the knob is being spinned.

Values of event.detail:

| Name | Type | Description | | -: | :-: | :- | | degree | number | Current degree | | lastDegree | number | Degree of last spinning event | | offsetDegree | number | Difference degree from the degree of beginning to degree |

spinend

Cancelable: false

Dispatches on the end of spinning.

Properties of event.detail is the same as spinstart.

License

Knob.js is MIT licensed.