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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sjaakp/dragzone

v1.0.2

Published

Dragzone with draggables

Downloads

6

Readme

Dragzone 1.0

Dragzone 1.0 is a JavaScript widget that transforms a <div>, or another HTML element, into a 'dragzone'. Such a 'dragzone' can host one or more 'draggables', other HTML elements which can be dragged within the zone. It was developed to be used for an online survey ('place point A to your favourite part of the city'), but may have other uses as well.

Dragzone 1.0 should work in any modern browser. It is small code, slightly under 3kB in size.

You can see Dragzone 1.0 in action here.

Here is Dragzone 1.0's GitHub page.

Install

Install Dragzone 1.0 with npm:

npm i @sjaakp/dragzone

You can also manually install Dragzone 1.0 by downloading the source in ZIP-format.

Dependencies

Dragzone 1.0 has no dependencies.

Usage

Load resources

Copy dragzone.js from the dist directory to a reachable subdirectory of your website. At the end of the body part of the HTML page, load the Dragzone 1.0 code like this:

<script src="/<your subdirectory>/dragzone.js"></script>

Load from CDN

You may also load the Dragzone 1.0 file from a content distribution network (CDN), like so:

<script src="https://unpkg.com/@sjaakp/knob/dist/dragzone.js"></script>

Set-up

Mark the dragzone with the attribute data-dragzone, and its draggable children with data-draggable, like this:

<div data-dragzone>
    <div data-draggable="draggable A">A</div>
    <div data-draggable="draggable B">B</div>
</div>

data-dragzone doesn't have a value (though it can, read on). The value of data-draggable is the name of the draggable. <div> is the obvious type of both dragzone and draggable, but many other types will work as well.

No further initializing is needed. An HTML page can have more than one, independent, dragzones.

Positions

The positions of the contained draggables are described in JSON format, for example:

{
"draggable A": {
    "x": "0.330",
    "y": "0.186"
    },
"draggable B": {
    "x": "0.274",
    "y": "0.816"
    }
}

The positions are indexed by the name of the draggable. The co-ordinates x and y are fractions of the dragzone's width and height, respectively. Therefore, they are floats between and including 0 and 1. They refer to the center point of the draggable.

Dragzone 1.0 reports the draggable positions by firing two events: "dragzone.changing" at the start of a dragging operation, and dragzone.changed at the end of it. In both cases, the JSON string describing the draggable positions is in the detail property of the event.

API

The JavaScript widget is stored as the dragzone property of the HTML element. It means that methods can be called like this:

document.getElementById("zone1").dragzone.disable(); // disable zone1

Dragzone 1.0 has four functions:

  • getPositions() get the draggable positions as JSON string;
  • setPositions(json) set the draggable positions from a JSON string;
  • enable() enable dragging operations (default);
  • disable() disable them.

Attributes

Dragzone 1.0's main attribute data-dragzone accepts a JSON string describing the draggable positions as value.

Add the attribute data-disable to take off with a disabled dragzone.

Attribute data-precision sets the precision of the position co-ordinates; default is 3.