Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vbarbarosh/dd

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vbarbarosh/dd

An abstraction for working with the mouse

  • 1.9.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

An abstraction for working with the mouse.

dd({
    event, // Pass original event object in
    begin: function (ctx) {
        console.log('The beginning');
    },
    end: function (ctx) {
        console.log('The end');
    },
    move: function (ctx) {
        console.log(`Position: x=${ctx.x} y={ctx.y}; distance: dx=${ctx.dx} dy=${ctx.dy}`);
    },
});

Installation

npm i @vbarbarosh/dd

Using from browser

<script src="https://unpkg.com/@vbarbarosh/dd@1.3.0/dist/dd.js"></script>

Description

This abstraction comes from the following observations:

  1. Each interaction with the mouse has the following workflow:

    mousedown -> mousemove ... mousemove -> mouseup
    

    (here is context.begin, context.end, and context.move).

  2. Almost always what you are really looking for is how far a mouse was moved from the beginning (here is context.dx and context.dy).

  3. In general, you have to work with 2 coordinate system: the screen coordinates, and local coordinates. And the only thing you are interested in is your local coordinates. Or, in other words, you have to convert coordinates from screen to local (here is context.translate).

Gotchas

  • IFRAME and BUTTON[disabled] stops propagation of mouse events. As a result dd will not call begin not update handlers (Events and disabled form fields).

Resources

Keywords

FAQs

Package last updated on 20 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc