Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Last active August 29, 2015 14:05
Show Gist options
  • Save ooflorent/ba8991296a169e2a0921 to your computer and use it in GitHub Desktop.
Save ooflorent/ba8991296a169e2a0921 to your computer and use it in GitHub Desktop.
Simple cursor selection

cursor

Change your mouse cursor without pain.

New API

var cursor = require('./cursor2');

cursor();           // Use 'default'
cursor('pointer');  // Use 'pointer'
cursor('grabbing'); // Use 'grabbing' or '-webkit-grabbing' or '-moz-grabbing'

Old API

var Cursor = require('./cursor');

Cursor.normal();    // Use 'default'
Cursor.hand();      // Use 'pointer'
Cursor.crosshair(); // Use 'crosshair'
function cursor(type) {
return function() {
document.body.style.cursor = type;
};
}
module.exports = {
normal: cursor(''),
hand: cursor('pointer'),
crosshair: cursor('crosshair'),
};
var bodyStyle = document.body.style;
var prefixes = ['', '-webkit-', '-moz-'];
module.exports = function(type) {
type = type || 'default';
for (var i = 0; i < 3; i++) {
bodyStyle.cursor = prefixes[i] + type;
if (~bodyStyle.cursor.indexOf(type)) return;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment