1.3.0 • Published 3 years ago

@vbarbarosh/dd v1.3.0

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

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.0.6/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

Links

1.3.0

3 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago