Ask Anvil

Answers to questions about automating PDFs, e-signatures, Webforms, and other paperwork problems.
E-signatures
Categories

Why does my signature pad scroll the page instead of drawing on a phone, and how do I fix it?

On desktop the signature canvas works. On a phone, dragging a finger across it scrolls the page, and you get a short dot or nothing at all.

The cause

After a pointerdown, if the browser decides the gesture is a pan, zoom, or scroll, it takes over and fires pointercancel. Your pointermove handler stops receiving events, so the stroke dies. The browser needs to be told this element handles its own dragging.

The fix

Set touch-action to none on the canvas.

canvas#signature { touch-action: none; }

Then draw with pointer events, which cover mouse, pen, and touch in one code path.

const canvas = document.querySelector("#signature");
const ctx = canvas.getContext("2d");
let drawing = false;

function point(e) {
  const rect = canvas.getBoundingClientRect();
  return { x: e.clientX - rect.left, y: e.clientY - rect.top };
}

canvas.addEventListener("pointerdown", (e) => {
  drawing = true;
  canvas.setPointerCapture(e.pointerId);
  const p = point(e);
  ctx.beginPath();
  ctx.moveTo(p.x, p.y);
});

canvas.addEventListener("pointermove", (e) => {
  if (!drawing) return;
  const p = point(e);
  ctx.lineTo(p.x, p.y);
  ctx.stroke();
});

canvas.addEventListener("pointerup", () => { drawing = false; });
canvas.addEventListener("pointercancel", () => { drawing = false; });

Why this works

touch-action: none disables browser handling of all panning and zooming gestures on the element. Because the browser no longer claims the gesture, the pointer events keep arriving. setPointerCapture makes later events for that pointer target the canvas until pointerup, so a stroke that drifts outside the canvas edge keeps drawing instead of dropping.

Caveats

Set the CSS up front. After a gesture starts, changing touch-action does not affect the current gesture.

Apply it only to the canvas, not the whole page. A full-screen signature surface traps users who need to scroll, so keep the pad a bounded size and leave the rest of the page scrollable.

Handle pointercancel anyway. It still fires in cases such as the browser deciding no more events are likely, and the handler above resets the drawing state.

Back to All Questions

The fastest way to build software for documents

Anvil Document SDK is a comprehensive toolbox for product teams launching document flows where PDF filling, signing, and complex conditional scenarios are necessary.
Explore Anvil
Anvil Webforms
Marketing Mode