1.0.16 • Published 7 years ago

trck v1.0.16

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

trck tracks the mouse/touch movement and apply to and especific element.


1. Install

npm install -S trck

2. Usage

import Trck from 'trck'

const track = new Trck({
    element: ".element-identifier",
    values:
        {
            x: true,
            y: true    
        },
    begin: function (element, {startX,startY}) { ... },
    progress: function (element, {startX, startY}, {currentX, currentY}) { ... },
    complete: function (element, {startX, startY}, {endX, endY}) { ... }

});

element

The identifier of the element that will be dragged.

values

An object that says which position will be watched. Use x: true to watch only the x position and y: true to watch the y position.

begin

Callback function to the mousedown/touchstart event. It receives as parameters the element, and an object with the x and y position on the start.

begin: function (element, beginPositions<Object>) {
    console.log(
        "Start positions: ",
        beginPositions.x,
        beginPositions.y
    );
}

//Start positions: 240, 120

progress

Callback function that is called in everytime mousemove/touchmove event is called. Receives the element and two objects as parameters: the start positions and the current positions.

progress: function (element, beginPositions<Object>, progressPositions<Object>) {
    console.log(
        "Start positions: ",
        beginPositions.x,
        beginPositions.y
    );
    console.log(
        "Progress positions: ",
        progressPositions.x,
        progressPositions.y
    );
}
//Start positions: 240, 120
//Progress positions: 360, 360

complete

Callback function that is called in the end of the movement. Receives the element and two objects as parameters: the start positions and the end positions.

complete: function (element, beginPositions<Object>, completePositions<Object>) {
    console.log(
        "Start positions: ",
        beginPositions.x,
        beginPositions.y
    );
    console.log(
        "Complete positions: ",
        completePositions.x,
        completePositions.y
    );
}
//Start positions: 240, 120
//Complete positions: 360, 360

3. Methods

getTransform()

Returns and object with the x and y position from the element.style.transform.

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago