A jQuery mousestop plugin to compliment other mouse events such as mousemove
, mouseout
and mouseout
coming in at ~1Kb minified.
The mousestop
event was created using the jQuery Special Events API and therefore can be binded like any other event.
The most basic usage is to pass in the callback for a stop event.
$('#el').mousestop(function() {
console.log("stopped")
});
We can also pass the delay
time in the second parameter to specify the amount of time to delay before a stop triggers. The default is 300 milliseconds
$('#el').mousestop(2000, function() {
console.log("stopped")
});
There is also a settings parameter called timeToStop
. This parameter specifies a window of time that the stop event has to occur. After that time the stop event will no longer trigger whatsoever. Leaving the value unset or setting it to null will deactivate this timer.
$('#el').mousestop({timeToStop: 1000}, function() {
console.log("stopped")
});
To set both a delay and a settings parameter.
$('#el').mousestop({delay: 400, timeToStop: 1000}, function() {
console.log("stopped")
});
We can also bind
and trigger
the event as you would expect with any other element.
$('#el').bind('mousestop', function(){
console.log('stopped');
});
$('#el').trigger('mousestop');
Since we are using the jQuery special API we can also use the on
method to bind the event as well.
$('#el').on('mousestop', function(){
console.log('stopped');
});
If you want to use Grunt you will need to install the required plugins locally using npm install
in the root folder of the project. If you need to setup Grunt on your system you can follow this Setting up Grunt.js guide.
- jQuery Special Events API
- More jQuery plugins by Websanova
- Websanova JavaScript Extensions Project
- jQuery Plugin Development Boilerplate
- The Ultimate Guide to Writing jQuery Plugins
MIT licensed
Copyright (C) 2011-2012 Websanova http://www.websanova.com