Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript how to change mouse cursor to an image?

I've seen examples where you can change it to preset images that your operating system has; example:

$('body').css('cursor', 'wait'); 

But how about my own /img/my_image.png?

Thanks for any help.

like image 200
JDS Avatar asked Jun 02 '12 22:06

JDS


People also ask

Can Javascript Move cursor?

You cannot move the actual mouse pointer in Javascript. You can, however move a pointer shaped image and pretend that you can. :-) Better yet, you can move a cat image around, following the mouse cursor, and try to use it to chase the cursor into the position you want.


2 Answers

You can, by specifying a url to it in CSS:

div {
    cursor: url(smiley.gif), url(myBall.cur), auto;
}

See http://www.w3schools.com/cssref/pr_class_cursor.asp

like image 160
malangi Avatar answered Sep 27 '22 20:09

malangi


The Jquery way to set a custom cursor (or default cursor as a fallback):

$('selector').css({'cursor': 'url(/cursors/customMoveCursor.cur), default'});
like image 24
Kalle Avatar answered Sep 27 '22 19:09

Kalle