Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fx.Scroll:toElementEdge #239

Open
wants to merge 2 commits into from

3 participants

@arian
Owner

Fix by @csuwldcat + some optimization done by me.

@csuwildcat csuwildcat Fixed bad logic in Fx.Scroll that failed to account for existing scro…
…ll offsets and offests that are larger than the element's right edge coordinates
9a175b5
@woomla

I have a small fix for it (see http://jsfiddle.net/woomla/h9eTx/6/). But I think it is because getPosition is changed in 1.3. I can't tell if getPosition should be fixed or toElementCenter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 21, 2011
  1. @csuwildcat @arian

    Fixed bad logic in Fx.Scroll that failed to account for existing scro…

    csuwildcat authored arian committed
    …ll offsets and offests that are larger than the element's right edge coordinates
Commits on Apr 24, 2011
  1. @arian
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 14 deletions.
  1. +9 −11 Source/Fx/Fx.Scroll.js
  2. +3 −3 Tests/Fx/Fx.Scroll_(element).html
View
20 Source/Fx/Fx.Scroll.js
@@ -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);
@@ -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(),
View
6 Tests/Fx/Fx.Scroll_(element).html
@@ -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');
Something went wrong with that request. Please try again.