@sparing-software/100vh
v1.2.0
Published
Lightweight JS package for easy overcoming the problem with 100vh on mobile devices
Downloads
65
Readme
100vh
Lightweight JS package for easy overcoming the problem with 100vh on mobile devices :iphone:
How does it work?
It creates the CSS variable called --vh
at the <html>
tag and vh
variable in the window
, which is changed only on orientation change and stays still during scroll. This will prevent the page "jumping" on scroll, which leads to bad user experience.
Important note:
This will stay still only on mobile devices, on desktop the value changes together with the viewport. That means that it can be used on any resolution and there is no need for additional css media queries.
Installation
Install package in your project
npm i @sparing-software/100vh
Initialization
Import the package and run the init function at the page start. (for Nuxt.js/Vue app it can be initialized in plugins, if you're using other technology – init the script above all the other code)
import vh from '@sparing-software/100vh'
vh.init()
Examples
CSS
.section {
height: var(--vh);
}
JS
window.querySelectorAll('section').style.height = window.vh
Contributing
Want to help improve this plugin? Great!
Project is open-source so fork repo and join us!
License
MIT License © Sparing Interactive