mouse-proximity.js
Track the distance between the mouse cursor and multiple elements
install
bower:
bower install mouse-proximity
npm:
npm install mouse-proximity
distribution file: dist/js/mouse-proximity.min.js
Use with vanilla js
//initialize options herevar mprox = document clear: true origin: 'center' showAttribute: false cb: //callback can be set here too; //callbackvar { //do something with the element (el) //dow something with the distance (distance)} //run the proximity trackermprox; //stop the proximity trackermprox;
Use with jQuery
//initialize options here; //callbackvar { //do something with the element (el) //dow something with the distance (distance)} //run the proximity trackerdata'mouseProximity'; //stop the proximity trackerdata'mouseProximity';
Options
clear
- type: boolean
- default: false
- for clearing the console so you don't end up with a huge list of mouse move logs (not really reliable)
origin
- type: string
- options: center (only one option for now)
- default: center
- set the origin relative to the body of the element from which to calculate distance from the mouse cursor
showAttribute
- type: boolean
- default: true
- add a data-mouse-proximity attribute to the element with its distance data
cb
- type: function
- default:
{ console;}
- callback function for doing whatever you want with the resulting distance data
Methods
run( callback( el, distance) )
starts a mousemove event and feeds the resulting data into the callback
stop()
unbinds the mousemove event and halts proximity tracking