Ticket #1151 (new defect)

Opened 4 years ago

Last modified 3 years ago

popup placement is incorrect if root element is in scrolled DIV

Reported by: EricShulman Owned by: EricShulman
Priority: undefined Milestone: 2.7.1
Component: core Version:
Severity: undefined Keywords:
Cc:

Description (last modified by EricShulman) (diff)

When a popup link is placed inside a DIV with style "overflow:scroll" or "overflow:auto" and that DIV is then scrolled, the position of the resulting popup appears further down the page that intended, because it is not adjusting for the relative scroll offset of the containing DIV. This tweak patches the Popup.place() function to calculate and subtract the current scroll offset from the computed popup position, so that it appears in the correct location on the page.

Add these functions:

window.findScrollOffsetX=function(obj) {
	var x=0;
	while(obj) {
		if (obj.scrollLeft && obj.nodeName!='HTML')
			y+=obj.scrollLeft;
		obj=obj.parentNode;
	}
	return -x;
}
window.findScrollOffsetY=function(obj) {
	var y=0;
	while(obj) {
		if (obj.scrollTop && obj.nodeName!='HTML')
			y+=obj.scrollTop;
		obj=obj.parentNode;
	}
	return -y;
}

and, in Popup.place, replace these lines:

var rootLeft = findPosX(root);
var rootTop = findPosY(root);

with:

var rootLeft = findScrollOffsetX(root) + findPosX(root);
var rootTop = findScrollOffsetY(root) + findPosY(root);

This fix has been successfully implemented at  http://www.TiddlyTools.com/#CoreTweaks

Change History

Changed 4 years ago by EricShulman

  • description modified (diff)

Changed 4 years ago by FND

  • owner changed from JeremyRuston to FND
  • status changed from new to assigned

Changed 3 years ago by MartinBudden

  • owner changed from FND to MartinBudden
  • status changed from assigned to new

Merge findScrollOffsetX and findScrollOffsetY into findScrollOffset function which returns an object

Changed 3 years ago by MartinBudden

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

Fixed in changeset:11273

The findScrollOffsetX and findScrollOffsetY functions were kept separate, since this follows the pattern used by other functions (eg findPosX and findPosY)

Changed 3 years ago by FND

  • status changed from closed to reopened
  • resolution fixed deleted

Turns out this breaks popup positioning on WebKit?-based browsers (Safari, Chrome). When the page is scrolled down, the popup is positioned too far up.

The required changes should probably go into findPosX and findPosY directly.

reverted in changeset:11712

Changed 3 years ago by FND

  • owner changed from MartinBudden to EricShulman
  • status changed from reopened to new

Changed 3 years ago by FND

  • milestone changed from 2.6 to 2.6.2

Changed 3 years ago by MartinBudden

  • milestone changed from 2.6.2 to 2.7.1

Milestone 2.6.2 deleted

Note: See TracTickets for help on using tickets.