Finding remainder of stepping by multiple beyond a limit Summary: Looking for more elegant version of Math.ceil(a/b)*b - a.

I'm writing code (QML Canvas) that draws a timeline, with tick marks every n pixels. 

// Stepping across the width of the window, drawing tick marks
for (var x=0; x&lt;windowWidth; x+=n) drawTickAndLabelAt(x);


The timeline can be scrolled such that time=0 moves off the left edge of the window. I need to figure out the correct x value to start at so that the ticks are still drawn at the same time. That value is the multiple of n that is just larger than the scroll offset, minus the scroll offset.

This is the naive representation of that formula:

var firstTickX = Math.ceil(scrollOffset/n)*n - scrollOffset;
for (var x=firstTickX; x&lt;windowWidth; x+=n) drawTickAndLabelAt(x);


This works, but the formula feels inelegant, referencing both variables twice. Can you think of a simpler code path (using modulus, I'm assuming) that I'm failing to think of?
Math.ceil(scrollOffset/n)*n - scrollOffset


gives you the difference between scrollOffset and the next multiple of n larger or equal to scrollOffset. This is equivalent to:

var firstTickX = (scrollOffset % n) ? n - (scrollOffset % n) : 0;