Read :hover pseudo class with javascript

前端 未结 5 1516
时光说笑
时光说笑 2020-11-29 11:55

I made a function that overwrite the the :hover of some elements on a page. It fades between the normal and the :hover effect. That for i had to create a .hover class in my

5条回答
  •  自闭症患者
    2020-11-29 12:14

    UPDATE: I somehow got this wrong. The below example doesn't work. See @bfavaretto's comment for an explanation.

    In Firefox, Opera and Chrome or any other browser that correctly implements window.getComputedStyle is very simple. You just have to pass "hover" as the second argument:

    
    
    
    
    
    
    
    
    
    

    But I don't believe there's yet a solution for Internet Explorer, except for using document.styleSheets as Gumbo suggested. But there will be differences. So, having a .hover class is the best solution so far. Not unclean at all.

提交回复
热议问题