Drag with snap!

I’m making a slider - the scrub button can be smoothly dragged anywhere along a bar marked with increments, but once the button is released, I want it to snap to the nearest increment.
Would I have an array variable containing the positions of the increments, and then examine that to see which is the nearest position, or is there a better way?