Skip to content

Pseudo-Class implementation. #1409

Answered by chrishtr
Tim-Liam-Hill asked this question in Q&A
Discussion options

You must be logged in to vote

My question is how, at a high level, would an implementation for this look?

One approach (which is what Chromium basically does) is to simply recompute style on every mouse move, based on the change of state for which element became hovered or not hovered. This sounds very slow (and it is very slow if implemented without optimizations), but can be highly optimized with the following techniques:

  • Skip the whole algorithm if there is not a style rule referencing :hover
  • Only recompute style when the hovered element actually changes, after doing the hit test for which element is hovered
  • Only invalidate style for the elements that gained or lost potential hover state

With these optimization…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@chrishtr
Comment options

Comment options

You must be logged in to vote
1 reply
@Tim-Liam-Hill
Comment options

Answer selected by Tim-Liam-Hill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants