Not sure if my use case is identical to what the question was originally asking for, but I found this question when trying to solve my case.
What I wanted to do was scroll such that vertical center of the viewport aligned with the vertical center of the target element.
The code I ended up using for this is as follows. This works by offsetting the scroll target by half of the difference between the viewport height and the element height.
Note: I think this code assumes the element is smaller than the viewport. To also handle cases where the element were larger than the viewport, you might need to modify this using an absolute value function or something. This wasn't necessary for my use case.
function scrollto (target) {
document.documentElement.scrollTop = document.body.scrollTop = target.offset().top - (window.innerHeight - target.height()) / 2;
}
scrollto($(this));