mootools/mootools-more — Issue #1099: toElementCenter (getScroll) scrolls to incorrect position
Author: ibolmo
Created: 2012-02-07 17:07:54+00:00
State: open

(from [Lighthouse](https://mootools.lighthouseapp.com/projects/24057-mootoolsmore/tickets/538-toelementcenter-scrolls-to-incorrect-position#ticket-538-3))

Hi,

When the container element's scroll position (vertical) is not zero, toElementCenter scrolls to an incorrect position. This is visible when you scroll to a certain element twice. The first time the containter scrolls so the element is in the center, the next time the container element is scrolled to the top (y < 0).

A little research showed that the current scroll position should be added to the equation:

to[axis] = scroll[axis] + position[axis] - (containerSize[axis] - size[axis]) / 2;

Discussion: http://groups.google.com/group/mootools-users/browse_thread/thread/...
Fiddle showing problem and solution: http://jsfiddle.net/woomla/D2nJJ/8/