Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Distance calculation and event handler
JavaScript CoffeeScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.md
jquery.vicinity.coffee
jquery.vicinity.js

README.md

Simple jQuery plugin to track the distance between an element and the mouse cursor.

Bind a listener to the update event like: $('.dropdown-toggle').vicinity().bind 'update', (e, distance) -> console.log distance

A distance of 0 means the mouse is on the element.

options:

  • target (defaults is document) You can set the target of the event listener to a different element than document. The event will only be triggered when the mouse hovers above that element.

If you just want to calculate the shortest distance between an element and a given point, you can use: $(el).distanceToPoint(x,y)

A nice way of using this is in combination with jquery.color, for instance:

$parent.css backgroundColor: $.Color('#fff').transition('#f00', ratio)

where the ratio is a value between 0.0 and 1.0 after dividing the distance by an arbitrary radius

Something went wrong with that request. Please try again.