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

joystick-controller

v2.0.0

Published

A JavaScript virtual joystick controller for both desktop and mobile devices.

Readme

Joystick Controller

npm GitHub License buyMeACoffee

joystick-controller

A fully customizable JavaScript virtual joystick controller for both desktop and mobile devices supporting multi instances. Live Demo

Installation

npm install joystick-controller

Quick Start

import JoystickController from "joystick-controller";

const joystick = new JoystickController({}, (data) => console.log(data));

JoystickController also supports CommonJS and global (CDN) import styles.

CDN / unpkg

<script src="https://unpkg.com/joystick-controller/dist/joystick-controller.umd.js"></script>
<script>
  // Unwrap the module namespace to get the class
  const JoystickController = window.JoystickController.default;
  const joystick = new JoystickController({}, (data) => console.log(data));
</script>

Browser Support

Requires the Pointer Events API, supported in all modern browsers (Chrome 55+, Firefox 59+, Safari 13+, Edge 12+).

Options

You can pass a set of options as the first argument to further customize your joystick controller.

| Name | Type | Default | Description | | --------------------- | -------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | maxRange | number | 100 | Maximum range of the joystick dot (number of pixels) | | level | number | 10 | Number of levels of the joystick (e.g. 10 returns integers between -10 and 10) | | radius | number | 50 | Radius of the joystick container (number of pixels) | | joystickRadius | number | 30 | Radius of the joystick inner dot (number of pixels) | | opacity | number | 0.8 | Opacity of the joystick | | containerClass | string | '' | Class for the joystick container for adding additional styles (outer container) | | controllerClass | string | '' | Class for the joystick controller for adding additional styles (inner container) | | joystickClass | string | '' | Class for the joystick dot for adding additional styles | | leftToRight | boolean | true | x position from left (ignored if dynamicPosition=true) | | bottomToUp | boolean | true | y position from bottom (ignored if dynamicPosition=true) | | x | string | '50%' | x position on screen — maps to CSS left/right (ignored if dynamicPosition=true) | | y | string | '50%' | y position on screen — maps to CSS bottom/top (ignored if dynamicPosition=true) | | distortion | boolean | false | If true, the joystick dot distorts visually when pushed to the edge | | dynamicPosition | boolean | false | Shows the joystick at the position where the user clicks/touches | | dynamicPositionTarget | HTMLElement | null | If dynamicPosition is true, listens for events on this element (defaults to document) | | mouseClickButton | string|number | "ALL" (-1) | Mouse button that activates the joystick (ALL, LEFT, MIDDLE, RIGHT, or a button number from -1 to 4; -1 for all) | | hideContextMenu | boolean | false | If true, suppresses the context menu on right-click (recommended with dynamicPosition) |

Callback Arguments

The callback fires on every move event and once on release (all values reset to 0).

| Name | Type | Description | | -------- | ------ | ---------------------------------------------------------------------------------------- | | x | number | x position of the joystick relative to its center | | y | number | y position of the joystick relative to its center | | leveledX | number | x scaled and rounded to an integer between -level and +level | | leveledY | number | y scaled and rounded to an integer between -level and +level | | angle | number | angle of the line from the center to the dot, in radians | | distance | number | distance of the dot from the center |

Customized Example

All options are optional. A fully customized instance looks like this:

// Static joystick
const staticJoystick = new JoystickController(
  {
    maxRange: 70,
    level: 10,
    radius: 50,
    joystickRadius: 30,
    opacity: 0.5,
    leftToRight: false,
    bottomToUp: true,
    containerClass: "joystick-container",
    controllerClass: "joystick-controller",
    joystickClass: "joystick",
    distortion: true,
    x: "25%",
    y: "25%",
    mouseClickButton: "ALL",
    hideContextMenu: false,
  },
  ({ x, y, leveledX, leveledY, distance, angle }) =>
    console.log(x, y, leveledX, leveledY, distance, angle)
);

// Dynamic position joystick
const dynamicJoystick = new JoystickController(
  {
    maxRange: 70,
    level: 10,
    radius: 50,
    joystickRadius: 30,
    opacity: 0.5,
    containerClass: "joystick-container",
    controllerClass: "joystick-controller",
    joystickClass: "joystick",
    distortion: true,
    dynamicPosition: true,
    dynamicPositionTarget: document.getElementById("root"),
    mouseClickButton: "ALL",
    hideContextMenu: true,
  },
  ({ x, y, leveledX, leveledY, distance, angle }) =>
    console.log(x, y, leveledX, leveledY, distance, angle)
);

Clean Up

Call destroy() to remove all event listeners and the joystick element from the DOM.

joystick.destroy();

Copyright(c) Cyrus Mobini 2024

License MIT