当类型为“auto”时获取实际游标

时间:2022-06-24 19:41:16

I'm using this code to get cursor type (using jQuery):

我用这段代码获取光标类型(使用jQuery):

$('*').mouseenter(function(){
    var cursor = $(this).css('cursor');
    console.log(cursor);
});

But on some elements it prints auto (which is the default option and means that the browser determine the cursor type).

但在某些元素上,它会打印auto(这是默认选项,意味着浏览器决定光标类型)。

I need to be able to know what the browser actually displays in those cases (i.e. pointer, resize, etc.)

我需要知道浏览器在这些情况下实际显示了什么(例如指针、调整大小等)。

For example: for a link element (tagName=A) it prints 'auto', but displays 'pointer'.

例如:对于链接元素(tagName= a),它打印'auto',但显示'pointer'。

How can I know which cursor type will be eventually displayed on the specific browser? In other words, how can I tell which cursor type the browser will choose?

我如何知道哪一种游标类型将最终显示在特定的浏览器上?换句话说,如何判断浏览器将选择哪种游标类型?

Is this behavior documented somewhere?

这种行为在什么地方被记录下来了吗?

2 个解决方案

#1


1  

This is determined by the user agent (=browser), which uses the platform specific default cursor for the element you are currently hovering.

这是由用户代理(=browser)决定的,它使用平台特定的默认游标作为当前悬停的元素。

general purpose cursors
'auto'
The UA determines the cursor to display based on the current context, specifically: auto behaves as text over text, and default otherwise.

通用游标'auto' UA根据当前上下文确定要显示的游标,特别是:auto在文本上表现为文本,否则默认。

So you cannot possibly tell what the cursor will look like when it is set to auto in the css.

因此,当它在css中被设置为auto时,您不可能知道游标会是什么样子。

I guessed there should be an overview which html element receives which cursor type so you could just decide based on the element type, but I could not find anything online. Also, there is no guarantee, that a certain browser will actually use that cursor, since auto gives them free reign, which cursor type to use.

我猜想应该有一个概述,html元素接收哪种光标类型,所以您可以根据元素类型来决定,但是我在网上找不到任何东西。另外,也没有保证,某个浏览器将实际使用该游标,因为自动提供了它们的*支配,这就是游标类型。

The only option to have control over this is to explicitely set the cursor to a specific type. (Also, I would be interested in a detailed use case where you need this).

唯一可以控制它的选项是显式地将光标设置为特定类型。(另外,我还对您需要的详细用例感兴趣)。

#2


0  

The browser determines your cursor as auto because it was never specified by your code. If you want to get the current cursor you would have to set it in your CSS or HTML explicitly for every element you would like to examine.

浏览器将光标确定为auto,因为您的代码从未指定它。如果您想要获取当前游标,您必须为您想要检查的每个元素显式地在CSS或HTML中设置它。

a {
   cursor: pointer;
}

After specifying it, .css('cursor') will return its type.

在指定它之后,.css(“光标”)将返回它的类型。

#1


1  

This is determined by the user agent (=browser), which uses the platform specific default cursor for the element you are currently hovering.

这是由用户代理(=browser)决定的,它使用平台特定的默认游标作为当前悬停的元素。

general purpose cursors
'auto'
The UA determines the cursor to display based on the current context, specifically: auto behaves as text over text, and default otherwise.

通用游标'auto' UA根据当前上下文确定要显示的游标,特别是:auto在文本上表现为文本,否则默认。

So you cannot possibly tell what the cursor will look like when it is set to auto in the css.

因此,当它在css中被设置为auto时,您不可能知道游标会是什么样子。

I guessed there should be an overview which html element receives which cursor type so you could just decide based on the element type, but I could not find anything online. Also, there is no guarantee, that a certain browser will actually use that cursor, since auto gives them free reign, which cursor type to use.

我猜想应该有一个概述,html元素接收哪种光标类型,所以您可以根据元素类型来决定,但是我在网上找不到任何东西。另外,也没有保证,某个浏览器将实际使用该游标,因为自动提供了它们的*支配,这就是游标类型。

The only option to have control over this is to explicitely set the cursor to a specific type. (Also, I would be interested in a detailed use case where you need this).

唯一可以控制它的选项是显式地将光标设置为特定类型。(另外,我还对您需要的详细用例感兴趣)。

#2


0  

The browser determines your cursor as auto because it was never specified by your code. If you want to get the current cursor you would have to set it in your CSS or HTML explicitly for every element you would like to examine.

浏览器将光标确定为auto,因为您的代码从未指定它。如果您想要获取当前游标,您必须为您想要检查的每个元素显式地在CSS或HTML中设置它。

a {
   cursor: pointer;
}

After specifying it, .css('cursor') will return its type.

在指定它之后,.css(“光标”)将返回它的类型。