Created
March 29, 2019 09:30
-
-
Save Langmans/039dce586889e899fea6ff87790bc9c0 to your computer and use it in GitHub Desktop.
This file contains 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
if (typeof assert !== 'function') { | |
function assert(expr, message) { | |
if (!Boolean(expr)) { | |
throw new Error(message || 'unknown assertion error'); | |
} | |
} | |
} | |
function elementScreenQuadrant(element) { | |
var type = typeof (element); | |
assert(type === 'object', 'element must be an object, got ' + type); | |
assert(element instanceof HTMLElement, 'element must be instance of HTMLElement, got ' + element.constructor.name); | |
assert(typeof element.getBoundingClientRect === 'function', 'element does not have getBoundingClientRect'); | |
var rect = element.getBoundingClientRect(); | |
var top = rect.top, | |
left = rect.left, | |
right = window.innerWidth - rect.right, | |
bottom = window.innerHeight - rect.bottom; | |
return (top > bottom ? 'bottom' : 'top') + (left > right ? 'right' : 'left'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment