npm.io
1.0.17 • Published 4 years ago

get-viewport-sizes

Licence
ISC
Version
1.0.17
Deps
0
Size
6 kB
Vulns
0
Weekly
0

Installation

npm install get-viewport-sizes

To use, call getSizes() at the top of your entry file to populate --vh and --vw

import { getSizes } from 'get-viewport-sizes';
getSizes(200); // where 200 (default) is the timeout for debounce 

You may then use the var in css like this

main {
    height: var(--vh * 0.8)  //80% of vh
}

React Hook

You may also use React hook to get the updated with and height

const { width, height } = useGetViewportSizes(200) // where 200(default) is the timeout for debounce

Hook will return width and height as float