pure javascript to check if something has hover (without setting on mouseover/out)

后端 未结 4 1002
死守一世寂寞
死守一世寂寞 2020-11-29 00:50

I have seen this jQuery syntax:

if($(element).is(\':hover\')) { do something}

Since I am not using jQuery, I am looking for the best way to

4条回答
  •  死守一世寂寞
    2020-11-29 01:37

    Simply using element.matches(':hover') seems to work well for me, you can use a comprehensive polyfill for older browsers too: https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

提交回复
热议问题