Experiments >

Code animation: Resize with snap

Experiment #16028th April, 2021by Joshua Nussbaum

In experiment #119, I worked out resizing elements. The resize happens at a single pixel resolution. But often you want to resize based on a grid.

It turns out, all it takes is rounding to the nearest grid position:

const gridSize = 10

function snapToGrid(width) }
  return Math.round(width / gridSize) * gridSize




view all experiments

Stay tuned in

Learn how to add more experimentation to your workflow