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

Ticket #7466 (closed defect: untested)

Opened 1 year ago

Last modified 5 months ago

realOffset with Opera gives junk results

Reported by: cjhicks Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: normal Keywords: opera realoffset
Cc:

Description

When using the latest version of Opera(9.10), the results from Position.realOffset do not reflect the real scroll offsets. This is because Opera appears to be putting the offsetTop and offsetLeft values into the scrollTop and scrollLeft attributes for some elements.

This can easily be verified by creating a table in html and outputing the scrollLeft and scrollTop attributes of various elements using javascript. Fooling around with the borders and cellspacing causes the scrollLeft and scrollTop values to shift around nicely. In my case this was happening on TR and TBODY elements and SPANs.

This is what I did to fix it in my code, but I didn't test the accuracy of the results with an element that has both scrollbars and a valid offsetLeft or offsetTop values.

  realOffset: function(element) {
   var valueT = 0, valueL = 0;
   do {
       if( !window.opera )
       {
          valueT += element.scrollTop  || 0;
          valueL += element.scrollLeft || 0;
       }
       else
       {
          var vT = element.scrollTop || 0;
          var vL = element.scrollLeft || 0;

          vT -= element.offsetTop || 0;
          vL -= element.offsetLeft || 0;
				
          if( vT > 0 )
            valueT += vT;
					
          if( vL > 0 )
            valueL += vT;
       }

       element = element.parentNode;
    } while (element);
    return [valueL, valueT];
  }

Change History

01/30/08 04:03:04 changed by kangax

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

Closing as untested. Please reopen if you find this failing with head revision.