如何获得:悬浮css样式的jQuery锚?

时间:2022-11-04 17:42:02

How can i get the :hover in css stylesheet on the fly with jquery?

如何使用jquery动态获取:悬浮在css样式表中?

stupid example:

愚蠢的例子:

a.foo {
    color: red;
    font-size: 11px;
}

a.foo:hover {
    color: blue;
    font-size: 12px; 
}

how to retrieve that color and font-size before that mouse will go over the anchor?

如何在鼠标经过锚点之前检索颜色和字体大小?

4 个解决方案

#1


4  

If you really need to, you can access this information throught the document.styleSheet property. An example is available here: http://jsfiddle.net/Xm2zU/1/

如果您确实需要,您可以通过文档访问此信息。样式表属性。这里有一个示例:http://jsfiddle.net/Xm2zU/1/

Please note that IE would need its own code to do this as it uses ".rules" rather than ".cssRules" etc.

请注意,IE需要自己的代码来实现这一点,因为它使用的是“.rules”而不是“。rules”。cssRules”等。

#2


1  

Take a look at Extra selectors for jQuery.

看看jQuery的额外选择器。

Also, you can use the hover event, depending on what you want to achieve. See: jQuery hover and class selector.

此外,您还可以使用鼠标悬停事件,这取决于您希望实现什么。参见:jQuery悬浮和类选择器。

#3


1  

how to retrieve that color and font-size before that mouse will go over the anchor?

如何在鼠标经过锚点之前检索颜色和字体大小?

No. You cannot retrieve the style declarations of a :hover pseudo class before hovering your mouse over that element. This is because JavaScript can only interact with the HTML using DOM. The style information (for the hovered state) is not available to the DOM unless there is a mouseover on the element and hence you cannot retrieve those values(even by simulating a hover state).

不。在将鼠标悬停在该元素上之前,不能检索a:hover pseudo类的样式声明。这是因为JavaScript只能使用DOM与HTML交互。除非元素上有鼠标悬停,否则DOM无法获取样式信息(对于悬停状态),因此不能检索这些值(甚至通过模拟悬停状态)。

#4


0  

You can use .hover() function instead. http://api.jquery.com/hover/

您可以使用.hover()函数代替。http://api.jquery.com/hover/

$( "a.foo" ).hover(
  function() {
    $( this ).css( 'color','red' );
  }, function() {
    $( this ).css( 'color','blue');
  }
);

#1


4  

If you really need to, you can access this information throught the document.styleSheet property. An example is available here: http://jsfiddle.net/Xm2zU/1/

如果您确实需要,您可以通过文档访问此信息。样式表属性。这里有一个示例:http://jsfiddle.net/Xm2zU/1/

Please note that IE would need its own code to do this as it uses ".rules" rather than ".cssRules" etc.

请注意,IE需要自己的代码来实现这一点,因为它使用的是“.rules”而不是“。rules”。cssRules”等。

#2


1  

Take a look at Extra selectors for jQuery.

看看jQuery的额外选择器。

Also, you can use the hover event, depending on what you want to achieve. See: jQuery hover and class selector.

此外,您还可以使用鼠标悬停事件,这取决于您希望实现什么。参见:jQuery悬浮和类选择器。

#3


1  

how to retrieve that color and font-size before that mouse will go over the anchor?

如何在鼠标经过锚点之前检索颜色和字体大小?

No. You cannot retrieve the style declarations of a :hover pseudo class before hovering your mouse over that element. This is because JavaScript can only interact with the HTML using DOM. The style information (for the hovered state) is not available to the DOM unless there is a mouseover on the element and hence you cannot retrieve those values(even by simulating a hover state).

不。在将鼠标悬停在该元素上之前,不能检索a:hover pseudo类的样式声明。这是因为JavaScript只能使用DOM与HTML交互。除非元素上有鼠标悬停,否则DOM无法获取样式信息(对于悬停状态),因此不能检索这些值(甚至通过模拟悬停状态)。

#4


0  

You can use .hover() function instead. http://api.jquery.com/hover/

您可以使用.hover()函数代替。http://api.jquery.com/hover/

$( "a.foo" ).hover(
  function() {
    $( this ).css( 'color','red' );
  }, function() {
    $( this ).css( 'color','blue');
  }
);