Created
January 28, 2019 14:34
-
-
Save olecksamdr/b215af0c9c64ac9d8762d22accea31c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function putContent(el: HTMLElement, currentPosition: string, isOpen: boolean): string { | |
let height = el.offsetHeight | |
var rect = el.getBoundingClientRect() | |
var elemTop = (isOpen ? rect.top : rect.top - height) | |
var elemBottom = (isOpen ? rect.bottom : rect.bottom + height) | |
if (elemTop <= 0) { return 'below' } | |
if (elemBottom >= window.innerHeight) { return 'above' } | |
return (isOpen ? currentPosition : 'below') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment