Created
April 4, 2018 00:24
-
-
Save blackakula/c5a8fbd0c23ac2e9631ba086b24b2f08 to your computer and use it in GitHub Desktop.
Browser window document width and height (very little piece of code, that saved my life)
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
const maxElementProperty = (element, ...properties) => Math.max( | |
0, | |
...properties.map(property => element ? element[property] : 0) | |
); | |
const realSize = (...documentElementProps) => (...bodyProps) => Math.max( | |
0, | |
maxElementProperty(document.documentElement, ...documentElementProps), | |
maxElementProperty(document.body, ...bodyProps) | |
); | |
export const width = realSize('clientWidth', 'offsetWidth', 'scrollWidth')('scrollWidth', 'offsetWidth'); | |
export const height = realSize('clientHeight', 'offsetHeight', 'scrollHeight')('scrollHeight', 'offsetHeight'); | |
export default {width, height}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Than in code: