alexdunphy / units

Got units? Convert them! Parse length, angle and resolution CSS values and convert between units.
MIT License
26 stars 7 forks source link

Conversion to % does not work with position: fixed elements #9

Open t10ko opened 3 years ago

t10ko commented 3 years ago

When you try to convert from PX to % on an element, which is a child of body and has fixed position, it will throw an error on utilities.getRelativeElementDimension, when trying to get element.offsetParent, which is null in that case.

The solution I propose is to add document.documentElement fallback to offsetParent: reference = positioned ? element.offsetParent || document.documentElement : element.parentNode;