Tips for web developers

Helpful tips to make you a better web developer!

Drag hysteresis

Drag hysteresis (aka drag threshold or start distance) is the intentional delay or buffer built into a drag-and-drop interaction

Instead of moving a block the absolute instant a user clicks and moves the mouse by a single pixel, the system waits until the mouse has traveled a specific distance (e.g., 3 to 5 pixels) or a certain amount of time has passed before it officially registers the action as a "drag"

Source gemini.google.com/share/1c4e05ebb65d

Create an 8px dead band so rows don't jitter back and forth right on the midpoint when dragging a block into a new position

Scroll anchoring

Scroll anchoring is a browser feature that tries to keep what you are looking at in the same visual position when content above or nearby changes size.

Example: You are halfway down a page, then an image above you finishes loading and becomes taller. Without scroll anchoring, everything below the image would jump downward. With scroll anchoring, the browser automatically adjusts the page scroll so your current reading position stays in place.

That is usually helpful. But in our case, it can be harmful.

On the moments page, the layout has:

left column: video / game player

right column: moment sidebar

When you click a moment in the right sidebar, the left player can change height, especially when switching between:

16:9 YouTube video

4:3 YouTube video

game replay player

Chrome may decide the clicked sidebar item is the “anchor” it wants to keep stable. So when the left player height changes, the browser adjusts the page scroll automatically. That makes it look like the right sidebar scrolled or jumped, even though our code did not call scrollTop, scrollTo, or scrollIntoView.

The fix I applied was:

.moment-watch-layout { overflow-anchor: none }

.moment-side-card-list.is-source-matched { overflow-anchor: none }

That tells the browser: “Do not use this area for automatic scroll anchoring.” So the browser stops trying to compensate when the media frame changes height.

This is different from restoring scrollTop. Restoring scrollTop says “let the jump happen, then move it back.” overflow-anchor: none prevents the browser from creating the jump in the first place.