Skip to content

Instantly share code, notes, and snippets.

View rcoelho's full-sized avatar

Rodrigo Coelho rcoelho

  • Rio de Janeiro, Brazil
View GitHub Profile
@rcoelho
rcoelho / keepheight.js
Last active July 18, 2019 15:48
Keep element height when the viewport is resized
/*
This gist will help you maintain your element's height when using vh units (viewport height)
on mobile devices despite the browser's navigation bar being shown/hidden or keyboard open/close,
preventing unexpected changes to the layout when the viewport resizes.
Useful for background cover images with 100vh height.
Try this if your page jumps up and down when the navigation bar is hidden and shown.
Tested only on mobile Chrome for Android.
Comments and improvements are welcome!
License: MIT.
*/