Skip to content

Commit

Permalink
fix for #4263, better support for nested fixed position elements
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonaaron committed Mar 19, 2009
1 parent 7c04a64 commit c0cdbf8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/offset.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ else
top = elem.offsetTop, left = elem.offsetLeft; top = elem.offsetTop, left = elem.offsetLeft;


while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) { while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) break;
computedStyle = defaultView.getComputedStyle(elem, null); computedStyle = defaultView.getComputedStyle(elem, null);
top -= elem.scrollTop, left -= elem.scrollLeft; top -= elem.scrollTop, left -= elem.scrollLeft;
if ( elem === offsetParent ) { if ( elem === offsetParent ) {
Expand All @@ -42,7 +43,7 @@ else
top += body.offsetTop, top += body.offsetTop,
left += body.offsetLeft; left += body.offsetLeft;


if ( prevComputedStyle.position === "fixed" ) if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" )
top += Math.max(docElem.scrollTop, body.scrollTop), top += Math.max(docElem.scrollTop, body.scrollTop),
left += Math.max(docElem.scrollLeft, body.scrollLeft); left += Math.max(docElem.scrollLeft, body.scrollLeft);


Expand All @@ -64,6 +65,10 @@ jQuery.offset = {
this.doesNotAddBorder = (checkDiv.offsetTop !== 5); this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
this.doesAddBorderForTableAndCells = (td.offsetTop === 5); this.doesAddBorderForTableAndCells = (td.offsetTop === 5);


checkDiv.style.position = 'fixed', checkDiv.style.top = '20px';
this.supportsFixedPosition = (checkDiv.offsetTop >= 15); // safari subtracts parent border width here which is 5px
checkDiv.style.position = '', checkDiv.style.top = '';

innerDiv.style.overflow = 'hidden', innerDiv.style.position = 'relative'; innerDiv.style.overflow = 'hidden', innerDiv.style.position = 'relative';
this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5); this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);


Expand Down

0 comments on commit c0cdbf8

Please sign in to comment.