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

Ticket #10149 (closed defect: wontfix)

Opened 2 years ago

Last modified 1 year ago

Element#cumulativeOffset doesn't include borderWidth

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

Description

Hi, I'm using prototype 1.6.0_rc1 and I noticed that for Firefox and IE the offsetLeft and offsetTop provided by those browsers is wrong in that it doesn't include borderWidths (Opera works perfectly however). For those two browsers this mostly fixes the problem:

  CumulativeOffset: function( element ) {
    var valueT = 0, valueL = 0;
    do {
      valueT += element.offsetTop  || 0;
      valueT += parseInt( Element.getStyle( element, 'borderTopWidth' ) ) || 0;
      valueL += element.offsetLeft || 0 ;
      valueL += parseInt( Element.getStyle( element, 'borderLeftWidth' ) ) || 0;
      element = element.offsetParent;
    } while (element);
    return Element._returnOffset(valueL, valueT);
  }

I say "mostly" because there is still an issue of pixelitis with IE (my offset is still off by 1 or 2 pixels, perhaps default padding or margin?). I suggest someone smarter than myself should implement the fix.

Change History

03/31/08 19:48:49 changed by kangax

  • summary changed from cumulativeOffset doesn't include borderWidth to Element#cumulativeOffset doesn't include borderWidth.

(follow-up: ↓ 3 ) 04/01/08 20:53:41 changed by jdalton

The fix for this issue is in this ticket:
http://dev.rubyonrails.org/ticket/11434

We should prolly make a patch.

(in reply to: ↑ 2 ) 04/01/08 21:36:39 changed by kangax

Replying to jdalton:

The fix for this issue is in this ticket:
http://dev.rubyonrails.org/ticket/11434
We should prolly make a patch.

It will probably fix this issue but leave us with bunch of other ones. I am trying to find as many references as possible for the cross-browser "way" to get element's offset . There are at least few other quirks that need to be taken into account : )

05/22/08 18:39:01 changed by jdalton

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

Won;t fix because the results are not consistent with rest of the methods.