Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Created January 28, 2019 14:34
Show Gist options
  • Save olecksamdr/b215af0c9c64ac9d8762d22accea31c5 to your computer and use it in GitHub Desktop.
Save olecksamdr/b215af0c9c64ac9d8762d22accea31c5 to your computer and use it in GitHub Desktop.
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