Skip to content

Instantly share code, notes, and snippets.

@jamesplease
Created June 1, 2018 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesplease/de2b863dbffc0b1fa02a5edf870d710d to your computer and use it in GitHub Desktop.
Save jamesplease/de2b863dbffc0b1fa02a5edf870d710d to your computer and use it in GitHub Desktop.
function adjustedBoundingBox(boundingBox) {
const overflowTop = Math.min(boundingBox.top, 0);
const overflowLeft = Math.min(boundingBox.left, 0);
const overflowRight = Math.min(window.innerWidth - boundingBox.right, 0);
const overflowBottom = Math.min(window.innerHeight - boundingBox.bottom, 0);
return {
top: Math.max(boundingBox.top, 0),
left: Math.max(boundingBox.left, 0),
height: boundingBox.height + overflowTop + overflowBottom,
width: boundingBox.width + overflowLeft + overflowRight
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment