toElementCenter (getScroll) scrolls to incorrect position #1099

Open
ibolmo opened this Issue Feb 7, 2012 · 1 comment

Projects

None yet

2 participants

@ibolmo
Member
ibolmo commented Feb 7, 2012 edited

(from Lighthouse)

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/

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/359847-toelementcenter-getscroll-scrolls-to-incorrect-position?utm_campaign=plugin&utm_content=tracker%2F22069&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F22069&utm_medium=issues&utm_source=github).
@challet
challet commented Apr 19, 2013

Agreed,
I always change the line you highlighted the same way you've done (adding scroll[axis])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment