1.0.1 • Published 3 years ago

get-hidden-height v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

get-hidden-height

v.1.0.1

getHiddenHeight is a function that takes a currently hidden element and returns its height as if it were visible. It works by invisibly cloning the element within its parent, measuring the height of the clone, then removing the clone from the parent.

This is useful for animating the height of a hidden element while making it visible.

Installation

npm install --save get-hidden-height

Usage

import getHiddenHeight from 'get-hidden-height';

getHiddenHeight(el, overrideStyles);

el - is the DOM element you want the height for.

overrideStyles - (optional) is an object of styles you want to apply to the element during its height calculation. This is useful if you need to constrain properties like max-height when the element is visible. By default max-height is set to none and will calculate the height based on this.

Return Value Returns the height of the element as an integer or null if the element does not exist.

Caveats

  • The parent container of the element must be visible for the calculation be accurate.

If you find any bugs or problems with this function, please create an issue and/or submit a pull request.