Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10245 (closed defect: fixed)

Opened 8 months ago

Last modified 6 months ago

Effect.scrollTo scrolls to top of page in firefox

Reported by: ultimasnake Assigned to: madrobby
Priority: normal Milestone: 2.x
Component: script.aculo.us Version: edge
Severity: normal Keywords:
Cc:

Description

Hi, i found a bug where Effect.scrollTo scrolls to the top of the page instead of scrolling to the item on the page.

The problem appears because the following code on line 514 (1.8.0) returns an invalid height in firefox 2. (in my case 810 in stead of 2120 pixels).

max = (window.height || document.body.scrollHeight) - document.viewport.getHeight();  

I did manage to create my own solution BUT it's not really the best way and also not implemented into the prototype. So my solution needs to be properly processed into the code.

Effect.ScrollTo = function(element) {
  var options = arguments[1] || { },
    scrollOffsets = document.viewport.getScrollOffsets(),
    elementOffsets = $(element).cumulativeOffset(),
    max = getBrowserHeight() - document.viewport.getHeight();  

  if (options.offset) elementOffsets[1] += options.offset;
  return new Effect.Tween(null,
    scrollOffsets.top,
    elementOffsets[1] > max ? max : elementOffsets[1],
    options,
    function(p){ scrollTo(scrollOffsets.left, p.round()) }
  );
};

getBrowserHeight = function(){
		if( window.innerHeight && window.scrollMaxY ){ // Firefox 
			pageHeight = window.innerHeight + window.scrollMaxY;
		}else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
		{
			pageHeight = document.body.scrollHeight;
		}else{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari 
			pageHeight = document.body.offsetHeight + document.body.offsetTop; 
		}
		return pageHeight;			
	},

Attachments

fix_firefox_scrolling_bug.diff (0.6 kB) - added by nik.wakelin on 01/17/08 23:14:16.
fix_firefox_scrolling_bug_with_tests.diff (2.7 kB) - added by nik.wakelin on 01/21/08 23:11:11.

Change History

11/22/07 13:05:45 changed by ultimasnake

I'm sorry in my rush to get back to work i submited this to the wrong component, can someone please edit this.

11/24/07 18:18:19 changed by josh

  • owner changed from core to madrobby.
  • component changed from ActiveRecord to script.aculo.us.

11/28/07 02:19:11 changed by ahecht

Ran into this bug too. It appears to be triggered by floats. (Possibly by other things, but at least by floats.)

Here's a test case that demonstrates the problem: http://www.cart-horse.com/test/ScrollToTest.html

01/17/08 23:13:18 changed by nik.wakelin

Hey,

I've added a patch that uses the prototype document.viewport.getScrollOffsets method rather than getBrowserHeight (I'm pretty sure they are equivalent, but correct me if I'm wrong).

No tests, but the change passes all the units and functionals :)

Nik

01/17/08 23:14:16 changed by nik.wakelin

  • attachment fix_firefox_scrolling_bug.diff added.

01/21/08 23:11:11 changed by nik.wakelin

  • attachment fix_firefox_scrolling_bug_with_tests.diff added.

01/21/08 23:11:29 changed by nik.wakelin

I've added tests as requested (in the new diff). They add a file, as the document height has to be 100% due to floats. (effects5b_test.html).

01/21/08 23:22:34 changed by madrobby

  • status changed from new to closed.
  • resolution set to fixed.

(In [8686]) script.aculo.us: Fix an issue with Effect.ScrollTo that caused Firefox to scroll to the wrong offset in some situations. Closes #10245.