Skip to content

Instantly share code, notes, and snippets.

@nshimiye
Last active May 22, 2019 02:46
Show Gist options
  • Save nshimiye/a41f95eb5c8396d9a0d24b738e7071f3 to your computer and use it in GitHub Desktop.
Save nshimiye/a41f95eb5c8396d9a0d24b738e7071f3 to your computer and use it in GitHub Desktop.
Tooltip check for off screen
checkOffScreen() {
const tipElement = this.tipRef.nativeElement;
const tipContent = this.tipContentRef.nativeElement;
const { left: tipElementLeft } = tipElement.getBoundingClientRect();
const { width: tipContentWidth } = tipContent.getBoundingClientRect();
const { right: bodyRight } = document.body.getBoundingClientRect();
this.isLeftOffScreen = tipElementLeft < tipContentWidth / 2;
this.isRightOffScreen = tipElementLeft + (tipContentWidth / 2) > bodyRight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment