jQuery 如何通过jQuery设置光标图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17389957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:57:32  来源:igfitidea点击:

How to set a cursor image via jQuery?

javascriptjqueryhtmlcss

提问by user1477955

Inside a web application I have a loading event. If the browser is loading data from the server, I want the cursor change to a gif that shows a clock. How can I change the cursor appearance. I only found this in the blog referring cursor apperance:

在 Web 应用程序中,我有一个加载事件。如果浏览器正在从服务器加载数据,我希望光标更改为显示时钟的 gif。如何更改光标外观。我只在博客中找到了这个引用光标外观:

$(this).css('cursor','move');

I want to load an image instead.

我想加载一个图像。

回答by Cherniv

Try this way:

试试这个方法:

$(this).css( 'cursor', 'url(cursor.png), auto' );

Here is JSFiddle: http://jsfiddle.net/fv3Bk/1/
The autoparameter tells what cursor type to use if cursor' image is not found. (See heremore cursor types, herethe example with another one )

这是 JSFiddle:http: //jsfiddle.net/fv3Bk/1/
auto参数告诉如果未找到光标图像,要使用的光标类型。(在这里查看更多游标类型,这里是另一个示例)

回答by Rick

If you want the cursor to be a cursor of your choice you can use the css cursor property like above, but with the url value:

如果您希望光标成为您选择的光标,您可以使用上面的 css cursor 属性,但使用 url 值:

$(this).css('cursor', 'url(/path/to/image),auto');

or to all inside the body:

或身体内的所有:

$('body').css('cursor', 'url(/path/to/image),auto');

As far as I know this won't work in Opera.

据我所知,这在 Opera 中是行不通的。