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

nanodrag

v2.0.0

Published

A small touchdrag events library

Downloads

16

Readme

nanodrag stability

npm version build status downloads js-standard-style

A small library to simplify the handling of drag events on mouse & touch devices.

Usage

const Nanodrag = require('nanodrag')
const div = document.createElement('div')
const nd = Nanodrag(div)

nd.on('start', (data) => {
  console.log('Drag started!', data)
})

nd.on('move', (data) => {
  console.log('Dragging!', data)
})

nd.on('end', (data) => {
  console.log('Drag finished!', data)
})

nd.close()

API

Properties

preventDefault:boolean

If this is set to true, it will call event.preventDefault() on the event provided by the touchmove or mousemove event. This property only works if you did not set {passive: true} in the constructor.

Examples:

This will attach the listener in passive mode and prevent the calling of event.preventDefault regardless of what value Nanodrag.preventDefault is.

const nd = new Nanodrag(element, {passive: true})

This will attach the listener in active mode allowing you decide to call event.preventDefault at a later time.

const nd = new Nanodrag(element)
nd.on('start', () => {
  nd.preventDefault = false
})

Methods

new Nanodrag(selector:string|element:HTMLElement, options?:object(key:any)):nanodrag

Create a new nanodrag instance. You can either pass in a valid selector for .querySelector or a reference to an HTML element. A nanodrag instance is also an instance of a nanobus object.

options

  • trackingDelay?:number - the delay (in nanoseconds) to wait before turning off the tracking mode if the mouse escapes the tracked element. Default: 300
  • passive?:boolean - attach touchmove and mousemove as passive listeners. This will prevent calling event.preventDefault on move events.

nanodrag#on(event:string, listener:function)

Provide a function to invoke when the specified event is triggered

nanodrag#once(event:string, listener:function)

Attach an event to invoke only once

nanodrag#emit(event:string, data:any)

Invoke an event with a specific payload of data

nanodrag#removeListener(event:string, listener:function)

Remove a specific listener

nanodrag#removeAllListeners(event?:string)

Remove all listeners for a given event; if no event is specified, removed all listeners.

nanodrag#close()

Remove all listeners on the DOM as well as on the nanobus instances and stop reporting any move events

Events

start

Triggered when a touch start or mouse down event occur on the nanodrag element.

data

  • start:object
    • x:number - the x coordinate of the touch instrument or mouse
    • y:number - the y coordinate of the touch instrument or mouse

move

Triggered when the mouse or touch instrument is moved after being started. For mouse-like devices, this means the button must be actively held down

data

  • start:object
    • x:number - the starting x coordinate of the touch instrument or mouse
    • y:number - the starting y coordinate of the touch instrument or mouse
  • current:object
    • x:number - the current x coordinate of the touch instrument or mouse
    • y:number - the current y coordinate of the touch instrument or mouse
  • direction:object
    • x:string - either 'left' or 'right
    • y:string - either 'up' or 'down

end

Triggered when the touchend or mouseup event occurs.

data

  • start:object
    • x:number - the starting x coordinate of the touch instrument or mouse
    • y:number - the starting y coordinate of the touch instrument or mouse
  • end:object
    • x:number - the end x coordinate of the touch instrument or mouse
    • y:number - the end y coordinate of the touch instrument or mouse

License

Copyright © 2018 Todd Kennedy, Apache 2.0 License