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

joystick-mv

v1.1.5

Published

Interactive on-screen joystick that allows users to control the movement of an HTML element in real-time

Downloads

76

Readme

Joystick-MV

Joystick-MV is a lightweight JavaScript library that provides an interactive on-screen joystick to control the movement of an HTML element in real-time. Ideal for web projects that require mobile control interaction or simulated movement using a visual control.

Demo

https://raxuk.github.io/joystick-move/

Features

  • Real-time control of an HTML element's movement.
  • Customizable speed and behavior.
  • Works on both desktop and mobile devices.
  • Easy integration and usage in any web project.
  • Designed with a modern and minimalistic style.

Installation

You can install the library via npm:

npm install joystick-mv

Or you can directly include it in your project by downloading the file.

Basic Usage Here is how you can use Joystick-MV in your project.

HTML

<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ejemplo de Joystick</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
        }

        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .movement-area {
            position: relative;
            height: 25vh;
            width: 25vw;
            border: 2px solid #e74c3c;
            margin-bottom: 20px;
        }

        .elementToMove {
            width: 100px;
            height: 100px;
            background-color: #3498db;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            cursor: move;
            user-select: none;
            border-radius: 50%;
        }

        .elementToMove2 {
            width: 50px;
            height: 50px;
            background-color: #39db34;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            cursor: move;
            user-select: none;
            border-radius: 50%;
        }

        .js-cont {
            display: flex;
            justify-content: space-around;
            width: 100%;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="movement-area">
            <div id='elM1' class="elementToMove">MOVE ME</div>
            <div id='elM2' class="elementToMove2"></div>
        </div>
        <div class="js-cont">
            <div id="joysticko"></div>
            <div id="joysticko2"></div>
        </div>
    </div>
</body>
<script type="module">
    import Joystick from './src/joystick.js';
    const js1 = new Joystick('joysticko', 'elM1', (position) => {
        console.log('Position:', position);
    }, 10);
    const js2 = new Joystick('joysticko2', 'elM2', (position) => {
        console.log('Position:', position);
    });
</script>

</html>

JavaScript

import Joystick from 'joystick-mv';

// Create a new joystick linked to an HTML element
const joystick = new Joystick('elementToAppend', 'elementToMove', (position) => {
    console.log('Current position:', position);
});

Parameters

The Joystick constructor accepts the following parameters:

  • elementToMoveId: The id of the HTML element that will be moved by the joystick.
  • onMoveCallback (optional): A callback function that receives the current position of the element (used to respond to real-time movement).
  • speed (optional): Defines the speed of the element's movement. The default value is 4.

Custom Styles

The joystick's style can be customized directly in your CSS. The library adds a main div (#joystick) and an inner div (#joystick-inner), representing the outer and inner parts of the joystick. You can modify their appearance to match your design.

By default, the joystick is designed with the following style:

#joystick {
  width: 100px;
  height: 100px;
  background-color: #2ecc71;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
}

#joystick-inner {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(0, 136, 204, 0.25);
}

Callback Example

You can define a callback to trigger actions when the element moves. For example, to update the position in real-time or perform calculations based on the current coordinates of the element:

const joystick = new Joystick('elementToAppend', 'elementToMove', (position) => {
    console.log('Current position of the element:', position.left, position.top);
}, 10);

Contributions

Contributions are welcome. If you encounter any issues or have suggestions to improve the project, please open an issue here or submit a pull request.

License

This project is licensed under the GPL-3.0 License.

Author

Created by raxuk. Thank you for using Joystick-MV!