Menu

You're Blocking Scroll by Default. `passive: true` Fixes It.
📰

You're Blocking Scroll by Default. `passive: true` Fixes It.

DEV Community: webdev·Parsa J·10 days ago
#GjfAZCRe
#devtowebdev#devto#dev#list#scroll
Reading 0:00
15s threshold

A teammate scrolled the product list on their phone and said it felt "sticky" — not broken, just a little behind, like the page was thinking about it before it moved. On a laptop trackpad it was perfectly smooth. Same code, same list, same 12-line scroll handler that did almost nothing: check scrollY , toggle a "back to top" button.

Twelve lines. Nothing in it that should cost more than a millisecond. And yet, on a phone, every scroll felt like it had a half-beat of drag.

The fix that didn't fix it

The obvious read is "the handler is too slow," so that's where the first hour went:

list . addEventListener ( " scroll " , () => { backToTop . hidden = list . scrollTop < 400 ; });

Enter fullscreen mode

Exit fullscreen mode

Wait — not even scroll . The actual listener was on touchmove , added so the button could react mid-gesture instead of waiting for the scroll to settle:

list . addEventListener ( " touchmove " , () => { backToTop . hidden = list .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.