@sect/100vh
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@sect/100vh

MIT license

Lightweight JS package for easy overcoming the problem with 100vh on mobile devices 📱

How does it work?

It creates the CSS variable called --vh at the <html> tag and vh variable in the window, which is changed on orientation change & resize event 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 @sect/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 '@sect/100vh';

vh.init();

Browser:

<!-- Include 100vh from dist -->
<script src="dist/100vh.umd.js"></script>
<!-- Initialize (you can do this whenever you want) -->
<script>
vh.init();
</script>

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

/@sect/100vh/

    Package Sidebar

    Install

    npm i @sect/100vh

    Weekly Downloads

    32

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    13 kB

    Total Files

    12

    Last publish

    Collaborators

    • sect