Skip to content

Commit

Permalink
Fix element overlays going off screen sometimes
Browse files Browse the repository at this point in the history
- On netflix the video element itself can be bigger than the screen
  • Loading branch information
killergerbah committed Apr 15, 2024
1 parent a97c7f3 commit e367439
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions extension/src/services/element-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,13 @@ export class CachingElementOverlay implements ElementOverlay {
const rect = this.targetElement.getBoundingClientRect();
container.style.left = rect.left + rect.width / 2 + 'px';
container.style.maxWidth = rect.width + 'px';
const clampedTop = Math.max(0, rect.top);

if (this.offsetAnchor === OffsetAnchor.bottom) {
container.style.top = rect.top + rect.height + window.scrollY - this.contentPositionOffset + 'px';
container.style.top = clampedTop + rect.height + window.scrollY - this.contentPositionOffset + 'px';
container.style.bottom = '';
} else {
container.style.top = rect.top + window.scrollY + this.contentPositionOffset + 'px';
container.style.top = clampedTop + window.scrollY + this.contentPositionOffset + 'px';
container.style.bottom = '';
}
}
Expand Down Expand Up @@ -481,12 +482,13 @@ export class DefaultElementOverlay implements ElementOverlay {
const rect = this.targetElement.getBoundingClientRect();
container.style.left = rect.left + rect.width / 2 + 'px';
container.style.maxWidth = rect.width + 'px';
const clampedTop = Math.max(0, rect.top);

if (this.offsetAnchor === OffsetAnchor.bottom) {
container.style.top = rect.top + rect.height + window.scrollY - this.contentPositionOffset + 'px';
container.style.top = clampedTop + rect.height + window.scrollY - this.contentPositionOffset + 'px';
container.style.bottom = '';
} else {
container.style.top = rect.top + window.scrollY + this.contentPositionOffset + 'px';
container.style.top = clampedTop + window.scrollY + this.contentPositionOffset + 'px';
container.style.bottom = '';
}
}
Expand Down

0 comments on commit e367439

Please sign in to comment.