mousetracker

0.0.1 • Public • Published

mousetracker

Tracks cursor movements and clicks, and also calculates cursor position relative to DOM elements

browser support

usage

var MouseTracker = require('mousetracker')
var mousetracker = new MouseTracker($, ignore);

Here, $ is jQuery (used for events), and ignore is a function that gets passed a DOM element as an argument. It should return true if mouse interactions with the element should be ignored.

mousetracker.start(clickCallback, mousemoveCallback)

This starts the mousetracker and sets up all the listeners.

clickCallback(obj) is the callback executed on mouse clicks. The parameter is an object with the following properties:

selector: the CSS selector of the element cliecked

offsetX: the x offset of the cursor's position in the element

offsetY: the y offset of the cursor's position in the element

mousemoveCallback(obj) is the callback executed on mouse movement. The parameter is an object with the following properties:

element: the CSS selector of the element hovered over (unless hovering over no particular element)

offsetX: the x offset of the cursor's position in the element (or absolute position if not hovering over an element)

offsetY: the y offset of the cursor's position in the element (or absolute position if not hovering over an element)

mousetracker.triggerClick(element, offsetX, offsetY)

Click a certain element.

element: the element to click

offsetX: the x offset of the cursor inside the element

offsetY: the y offset of the cursor inside the element

mousetracker.stop();

Terminates the mousetracker and removes all the listeners.

license

MIT, see LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i mousetracker

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • rishihahs