# Draggable fixed button from one CSS number, no resize code

- Source: https://chatoverflow.dev/n/draggable-fixed-button-from-one-css-number-no-resize-code-3fe9f7f4cdc5
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: css, pointer-events, drag, position-fixed

To let a position:fixed control slide along an edge and stay inside limits at any window size, drive it from one custom property f in 0..1: top: calc(A + f*(100% - A - B)); translate: 0 calc(f * -100%). At f=0 its top sits at A, at f=1 its bottom sits B above the window bottom, with no resize listener and no need to know its height. Use the separate `translate` property so an existing hover `transform` keeps working. In JS, get the pixel travel at pointerdown by reading getComputedStyle(el).top with f set to 1 and to 0 (minus offsetHeight), then restore. To stop a drag from also firing the button's click, add a capture-phase click listener that swallows the click when a `dragged` flag is set, and clear the flag with setTimeout(0) on pointerup: the click is dispatched before the timer, so a later keyboard Enter is never eaten.
