最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Changing mouse icon thru javascript - Stack Overflow

programmeradmin0浏览0评论

I am developing paintbrush application in javasript using Canvas Object. I want to change my own mouse cursor when the mouse pointer es inside Canvas object. How to load my own icon?

I am developing paintbrush application in javasript using Canvas Object. I want to change my own mouse cursor when the mouse pointer es inside Canvas object. How to load my own icon?

Share Improve this question edited Mar 6, 2010 at 0:34 Jon Seigel 12.4k8 gold badges60 silver badges93 bronze badges asked Feb 14, 2010 at 14:50 SoftSoft 1,8145 gold badges21 silver badges31 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

This can be acplished in CSS.

canvas {
    cursor: url(cursor.cur), url(cursor.gif), auto;
}

IE, Firefox, Safari, and Chrome will use the .cur file. The GIF (or use a PNG) is intended for browsers that don’t support the .cur file (not sure if there are any like this). Opera does not support custom cursors.

The size of the image must be 32x32 pixels or lower. This is a (Windows) OS restriction; not a browser restriction.

Reference - Quirksmode CSS patibility tables http://www.quirksmode/css/cursor.html

Do you have a .cur file for your own custom cursor?

You can have inside your Canvas object a style attribute that tells how the cursor should be shown as. This can be done through a custom css cursor

style="cursor: url(mycursor.cur);"
  1. IE expects a .cur file.
  2. Firefox requires a second, non-URL value; like cursor: url(pix/cursor_ppk.gif), auto.
  3. The size of the image must be 32x32 pixels or lower. This is a (Windows) OS restriction; not a browser restriction.

Taken from CSS2 - Cursor styles, it is patible in IE5.5+, FF, Safari and Chrome. Opera and Konqueror 3.5.7 is not patible.

There is a way: http://beradrian.wordpress./2008/01/08/cross-browser-custom-css-cursors/ Dose not work with Opera, but fine for IE, FF, Safari, Chrome.

I posted workaround for opera using js here: Opera and Custom cursor in CSS

发布评论

评论列表(0)

  1. 暂无评论