Skip to content

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

License

Notifications You must be signed in to change notification settings

rishihahs/mousetracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published