Skip navigation
browsers mostly skip updating hover state while you scroll
0:00 / 0:21

browsers mostly skip updating hover state while you scroll

daniel petho

@nonzeroexitcode8.3K followers

Visit on X
2,659 likesDownloadOriginal post

138,699 views

browsers mostly skip updating hover state while you scroll so I made super-hover, a tiny utility library that checks what's under your cursor every frame! `pnpm add super-hover`

61 Comments

Comments from the original post on X (Twitter)

  • daniel petho's profile picture

    @nonzeroexitcode

    so why would you use this? well, you probably shouldn't. deprioritizing hover updates is most likely done for performance, so browsers can focus on scrolling, painting and any layout work needed as new elements enter the viewport. which is probably what you want by default!

    82 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    BUT :) updating hover every frame opens up some fun interactions, like this super sick section by Locomotive, which first gave me the idea a while ago:

    71 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    I noticed myself recreating this functionality for the 3rd time for various personal projects and wished this existed, so here it is now

    42 likes

  • Diego Rodriguez's profile picture

    @asciidiego

    yo u should check @_chenglou midjourney gallery for an even simpler approach! in particular, the part about non-throttled cursor updates:

    29 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    @_chenglou oh, how many times you showed his site to us haha, and i still missed (or forgot) about this part... thank u!!

    5 likes

  • Shannon Code's profile picture

    @Shannoncode

    Can we please start shipping prompts already instead of shipping random npm packages?

    12 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    you can def get to this in a few prompts, but at this point it would make more sense to just point the agent to your codebase and describe on which elements you want to achieve an effect like this. so i don’t think it makes too much sense to publish a general prompt but also if you are only worried about installing an npm pkg, you can also point your agent to the codebase on github and say, hey copy this without installing or something code is super short and doesnt have any runtime deps:)

  • Shannon Code's profile picture

    @Shannoncode

    I just mean in general, and now days it’s almost safer to ship instructions to an agent than an npm package.

    1 like

  • DAKOKI's profile picture

    @yousifADK

    hmm but how bad is it really for performance? Could it be worth it to add a nice touch to prod? Interesting!

    11 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    it is def worse than just using the default `:hover` so I'd say it depends on your use-case: If it's for some fun creative effects, landing pages / portfolios, for sure, but i'd def avoid it for webapps or anywhere where perf is super super important will do some benchmarks later to get a more accurate picture tho

    6 likes

  • Codedgar's profile picture

    @codedgar_dev

    This should throttle or have performance considerations no?

    6 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    yes, certainly haha will try to do some benchmarking later to get a more accurate picture how much worse it is tho

    1 like

  • Nikil Kuruvilla's profile picture

    @NikilKuruvilla

    @AndrewPrifer Interesting I build an npm package called virtual-text-layout that uses pretext alongside Tanstack virtual to do infinite scrolls. I do have a live demo link on the package page.

    5 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    @AndrewPrifer uu this seems interesting, i’ll take a look!

    1 like

  • vie ⟢'s profile picture

    @viemccoy

    AWESOME!!!!!!!!

    4 likes

  • Meefs's profile picture

    @theycallmeken

    how you gonna show us selected ambient works and have no audio 😭😭

    4 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    🫶

  • Ankur's profile picture

    @ankur5ahu

    No visible frame drops on react-scan. Thats optimised like crazy. Also im curious is there any other way of doing this? like we can calculate where we are on the container and according to the height of each element we can determine which element is active? @jh3yy

    3 likes

  • daniel petho's profile picture

    @nonzeroexitcode

    1. yeah react-scan can be a good proxy, but it doesn't give a full picture eg. on a more complex site with more elements, where the browser has to do much more work, I'd expect bigger differences between this and native :hover. I'll try to do some proper benchmarking later to get a more accurate picture tho 2. yeah you're right! as @asciidiego also pointed out, this can be achieved much more simply (and prob more performant) if you know your elements' positions/heights/layout etc: I think this library maybe has a place as a drop-in solution where you don't know, or don't want to manage all of that yourself - eg arbitrary tall elements, unknown layouts, framework rendered lists, etc. or idk, maybe I'm just trying to justify the work I did for this in hindsight hahah

    3 likes

  • Quentin Merabet's profile picture

    @QuentinMerabet

    @AndrewPrifer @devenini + @plcossette coded

    2 likes