Chrome extension custom cursor

和自甴很熟 提交于 2019-12-04 07:30:51

As it turned out to make it work css rule should be written as: {cursor:url(...),default;}

For your 3rd method try this in css

#myImgId {
 cursor:url('chrome-extension://__MSG_@@extension_id__/icons/cursor.cur');
}

(doesn't work due to a bug)

You shouldn't need a Chrome extension for this; it's a standard feature of CSS to be able to change the cursor when moving over elements, including the ability to change it to a custom image.

You should be able to just add something like this to your CSS:

.myimage { cursor: url(icons/cursor.gif);}

without having to do any scripting at all.

However there are bugs, quirks and implementation differences in this feature in a variety of browsers.

The biggest quirk to know about is that Internet Explorer expects the cursor file to be a .cur file, whereas all other browsers expect a regular image file (eg a .gif). If you want it to work cross-browser, you will need to provide two versions of your icon and use a browser-specific test or hack in your CSS to make it pick the right one.

A very good summary of the CSS cursor feature with its quirks and support in various browsers can be found here: http://www.quirksmode.org/css/cursor.html

This page also states that "the image is garbled in Chrome". This may be bad news for you, but the test hasn't been updated for a while so that info applies to Chrome 5, so if there was bug there it may well have been fixed by now.

To add:

var css = 
'<Style id="myCursor">\n'+
' .myClass { cursor: url('+chrome.extension.getURL("Cursors/myCrossCursor.cur")+'), crosshair; }\n'+
'</Style>';
if ($("head").length == 0) { 
  $("body").before(css);
} else {
  $("head").append(css);
}

To remove:

$("#myCrossCursor").remove();

Do not forget to add the .cur file to the manifest:

"web_accessible_resources": [
  "Cursors/myCrossCursor.cur",
  ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!