Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Source/Fx/Fx.Scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,20 @@ Fx.Scroll = new Class({
toElementEdge: function(el, axes, offset){
axes = axes ? Array.from(axes) : ['x', 'y'];
el = document.id(el);
var to = {},

var to = {x: 0, y: 0},
position = el.getPosition(this.element),
size = el.getSize(),
scroll = this.element.getScroll(),
containerSize = this.element.getSize(),
edge = {
x: position.x + size.x,
y: position.y + size.y
};
containerSize = this.element.getSize();

['x', 'y'].each(function(axis){
if (axes.contains(axis)){
if (edge[axis] > scroll[axis] + containerSize[axis]) to[axis] = edge[axis] - containerSize[axis];
if (position[axis] < scroll[axis]) to[axis] = position[axis];
var edge = position[axis] + size[axis];
to[axis] = (edge > containerSize[axis]) ? edge - containerSize[axis]
: ((position[axis] < scroll[axis]) ? position[axis] : 0);
}
if (to[axis] == null) to[axis] = scroll[axis];
if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
to[axis] += scroll[axis] + ((offset && offset[axis]) ? offset[axis] : 0);
}, this);

if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
Expand All @@ -142,7 +139,8 @@ Fx.Scroll = new Class({
toElementCenter: function(el, axes, offset){
axes = axes ? Array.from(axes) : ['x', 'y'];
el = document.id(el);
var to = {},

var to = {x: 0, y: 0},
position = el.getPosition(this.element),
size = el.getSize(),
scroll = this.element.getScroll(),
Expand Down
6 changes: 3 additions & 3 deletions Tests/Fx/Fx.Scroll_(element).html
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@
},
{
title: 'Scroll to top of the red item.',
fn: fx.toElement.bind(fx, 'red')
fn: fx.toElement.pass(['red'], fx)
},
{
title: 'Scroll the blue item into view.',
title: 'Scroll the blue element edge.',
fn: function(){
fx.set(0,0);
fx.toElementEdge('blue', 'y');
}
},
{
title: 'Scroll the yellow item into view (from below).',
title: 'Scroll the yellow element edge (from below).',
fn: function(){
fx.set(0,500);
fx.toElementEdge('yellow', 'y');
Expand Down