StealThis .dev

Long Press Menu

A context menu triggered by a long press (500ms hold) on mobile, and right-click on desktop. Dismisses on outside tap or Escape. No libraries.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Long Press Menu

A context menu that appears after a 500ms press-and-hold on mobile, and on right-click for desktop users. The menu positions itself near the press point while staying within the viewport.

How it works

  1. touchstart starts a 500ms setTimeout; touchmove or touchend cancels it
  2. When the timer fires, the press coordinates are recorded and the menu is shown
  3. Desktop users can also trigger it via contextmenu (right-click)
  4. The menu position is clamped so it never overflows the viewport edges
  5. Tapping outside or pressing Escape dismisses the menu

Features

  • Works on grid items, list items, images, or any element with data-long-press
  • A haptic-style visual pulse animation plays on the pressed element
  • Menu items can carry data-action attributes for event handling

When to use it

  • Photo galleries (select, share, delete)
  • File browsers
  • Social feed cards (react, share, save, report)