toElementCenter

44 views
Skip to first unread message

woomla

unread,
Mar 4, 2011, 3:57:43 AM3/4/11
to MooTools Users
Hi,

I've created a large list of div's in a container div. I want the
container to scroll programmatically to some element. So I suppose to
use toElementCenter. But it appears that the calculation is wrong, or
my interpretation of the function is wrong. I hope someone can clarify
this for me.

See this fiddle: http://jsfiddle.net/CB7Xj/17/

The first few functions create the list and put the items in a results
array. At the bottom of the script we start to scroll to all elements
one by one with function mooScrollTo. In the output you see some
scrolling, but at some point it is going up and down again.

Ryan Florence

unread,
Mar 4, 2011, 10:18:21 AM3/4/11
to mootool...@googlegroups.com
I didn't bother interpreting your example but made this example instead.

http://jsfiddle.net/rpflorence/D2nJJ/

This appears to work as expected. It scrolls one element to the center of another element.

woomla

unread,
Mar 6, 2011, 5:05:49 PM3/6/11
to MooTools Users
Thanks.

And what happens if we center the element twice?

http://jsfiddle.net/D2nJJ/6/

woomla

unread,
Mar 8, 2011, 4:35:11 AM3/8/11
to MooTools Users
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

http://jsfiddle.net/woomla/D2nJJ/8/

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.

Aaron Newton

unread,
Mar 14, 2011, 2:56:13 PM3/14/11
to mootool...@googlegroups.com, woomla
Most of this thread needs to move to lighthouse. I can do that for you, but then you won't get emails as we work on it. Would you care to open a ticket? You can also create a pull request on github and send us the fix, which makes us love you even more.

woomla

unread,
Mar 14, 2011, 4:56:18 PM3/14/11
to MooTools Users
Already created a ticket (actually two tickets).

But I'm not sure what the fix should be because after some debugging I
see that getScrolls behaves different in 1.3 than 1.2, thus breaking
the functionality of toElementCenter and possibly more. It boils down
that getScrolls now uses this.parentNode (see
https://github.com/mootools/mootools-core/commit/6c9fda19070de685ebbbe71dd2128fe28f13f6ee).

It leaves us with some options like fix toElementCenter or revert
getScrolls. But I cannot see the consequences of these actions so I
hope you guys jump in on this.

Ticket toElementCenter:
https://mootools.lighthouseapp.com/projects/24057-mootoolsmore/tickets/538-toelementcenter-scrolls-to-incorrect-position.
Ticket getScrolls:
https://mootools.lighthouseapp.com/projects/2706-mootools/tickets/1192-getscrolls-is-different-in-13-and-breaks-toelementcenter.
Reply all
Reply to author
Forward
0 new messages