After some puzzling I believe that the function to calculate the new
scroll position needs to add scroll[axis] to it. So that line becomes:
to[axis] = scroll[axis] + position[axis] - (containerSize[axis] -
size[axis]) / 2;
This seems to work perfectly for me, at least for the vertical
scrolling that I tested. See
The first two time it uses the mootools function. The second time the
element is scrolled out of view.
The third and forth time it uses the altered function. The third time
it centers the element. The forth time the element stays centered.