{"id":13852724,"url":"https://github.com/Hiswe/vh-check","last_synced_at":"2025-07-13T06:30:58.744Z","repository":{"id":52191422,"uuid":"60515094","full_name":"Hiswe/vh-check","owner":"Hiswe","description":"mobile vh unit utility","archived":false,"fork":false,"pushed_at":"2024-04-23T01:48:36.000Z","size":686,"stargazers_count":439,"open_issues_count":11,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-06-22T22:02:19.225Z","etag":null,"topics":["android","buggyfill","chrome","css","ios","vh"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/vh-check","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hiswe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-06T09:18:09.000Z","updated_at":"2025-05-22T09:47:27.000Z","dependencies_parsed_at":"2024-06-18T13:44:15.306Z","dependency_job_id":"79bc66be-c6ae-47bc-aff3-15f3effd3ad2","html_url":"https://github.com/Hiswe/vh-check","commit_stats":{"total_commits":133,"total_committers":2,"mean_commits":66.5,"dds":"0.015037593984962405","last_synced_commit":"e06b39734a34da00141273b51bf68e6e315f4c1f"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/Hiswe/vh-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hiswe%2Fvh-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hiswe%2Fvh-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hiswe%2Fvh-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hiswe%2Fvh-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hiswe","download_url":"https://codeload.github.com/Hiswe/vh-check/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hiswe%2Fvh-check/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265098894,"owners_count":23711217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","buggyfill","chrome","css","ios","vh"],"created_at":"2024-08-04T22:01:34.519Z","updated_at":"2025-07-13T06:30:58.460Z","avatar_url":"https://github.com/Hiswe.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# vh-check\n\nget reliable CSS `vh` sizes for [1kb gzipped](https://bundlephobia.com/result?p=vh-check)\n\n[![npm version](https://badge.fury.io/js/vh-check.svg)](https://badge.fury.io/js/vh-check) [![Build Status](https://travis-ci.org/Hiswe/vh-check.svg?branch=master)](https://travis-ci.org/Hiswe/vh-check)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [the problem](#the-problem)\n- [why not use viewport-units-buggyfill?](#why-not-use-viewport-units-buggyfill)\n- [use](#use)\n  - [as a global variable](#as-a-global-variable)\n  - [as a commonJS module](#as-a-commonjs-module)\n  - [as a ES module module](#as-a-es-module-module)\n  - [how it works](#how-it-works)\n  - [returned object](#returned-object)\n- [example](#example)\n  - [in your javascript](#in-your-javascript)\n  - [in your CSS](#in-your-css)\n- [configuration](#configuration)\n  - [as a string](#as-a-string)\n  - [as an object](#as-an-object)\n    - [cssVarName](#cssvarname)\n    - [force](#force)\n    - [bind](#bind)\n    - [redefineVh](#redefinevh)\n    - [updateOnTouch](#updateontouch)\n    - [onUpdate](#onupdate)\n- [about browser support](#about-browser-support)\n- [demo](#demo)\n  - [github pages](#github-pages)\n  - [local](#local)\n- [caveats](#caveats)\n- [other stuff](#other-stuff)\n  - [changelog](#changelog)\n  - [migrating](#migrating)\n  - [run the tests](#run-the-tests)\n  - [thanks](#thanks)\n  - [related](#related)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## the problem\n\nBrowsers don't always compute the [vh unit](https://developer.mozilla.org/en-US/docs/Web/CSS/length#vh) the same way.\nSome mobile browsers compute the `vh` CSS unit without taking care of the url bar.\nThat means that a `100vh` div will overflow the viewport by the size of the url bar.\n\nThis is the current behavior for:\n\n- [Safari iOS](https://bugs.webkit.org/show_bug.cgi?id=141832)\n- [Chrome android \u003e= 56](https://developers.google.com/web/updates/2016/12/url-bar-resizing)\n\nAs explained in the chrome post, that make sense but make it hard to have a full [hero top block](https://line25.com/articles/30-web-designs-that-fully-embrace-the-hero-image).\n\nThis script will measure the difference and put it in a CSS var.\nYou can read more on this [css-trick article](https://css-tricks.com/the-trick-to-viewport-units-on-mobile/#article-header-id-0) by [Louis Hoebregts](https://css-tricks.com/author/louishoebregts/)\n\n\u003cimg src=\"https://unpkg.com/vh-check/issue-schema.svg\" width=\"200\" style=\"display: block; margin: 0 auto\"/\u003e\n\n## why not use viewport-units-buggyfill?\n\nIt's doing a very good job:\n\nhttps://github.com/rodneyrehm/viewport-units-buggyfill\n\nBut it has some problems with media-queries:\n\nhttps://github.com/rodneyrehm/viewport-units-buggyfill/issues/13\n\n## use\n\n### as a global variable\n\n```html\n\u003cscript src=\"https://unpkg.com/vh-check/dist/vh-check.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  (function () {\n    // initialize the test\n    var test = vhCheck();\n  }());\n\u003c/script\u003e\n```\n\n### as a commonJS module\n\n```\nnpm install vh-check\n```\n\n```js\nvar check = require('vh-check')\nvar test = vhCheck() // return an object (see below)\n```\n\n### as a ES module module\n\n```\nnpm install vh-check\n```\n\n```js\nimport vhCheck from 'vh-check'\nconst test = vhCheck()\n```\n\n### how it works\n\n- It will update the `vh-check` CSS custom property if needed\n- `vh-check` will be updated on `orientationchange` [event](https://developer.mozilla.org/en-US/docs/Web/Events/orientationchange)\n- `vh-check` **will not** be updated on scroll event by default\n\n### returned object\n\nvh-check will return a full object:\n\n```js\n{\n  isNeeded: false,\n  // wether or not it's needed\n  value: 0,\n  // the CSS var value\n  vh: 480,\n  // a 100vh div size\n  windowHeight: 480,\n  // same value as window.innerHeight\n  offset: 0,\n  // difference between the above sizes\n  recompute: function computeDifference(),\n  // call this to programmatically get all the values and set the CSS var\n  // - this can be useful if you want to add your own listeners\n  //   that will trigger a computation\n  unbind: function unbindVhCheckListeners(),\n  // call this to remove any window listeners created by vh-check\n},\n```\n\n## example\n\n### in your javascript\n\n```js\nvhCheck()\n```\n\n### in your CSS\n\n```css\nmain {\n  height: 100vh;\n  /* If you need to support browser without CSS var support (\u003c= IE11) */\n  height: calc(100vh - var(--vh-offset, 0px));\n  /* enable vh fix */\n}\n```\n\n## configuration\n\n### as a string\n\nYou can pass the CSS var name as a param to `vhCheck()` (default `vh-offset`)\n\n```js\nvhCheck('browser-address-bar')\n```\n\nIn your CSS you will have to reference:\n\n```css\nmain {\n  min-height: 100vh;\n  min-height: calc(100vh - var(--browser-address-bar, 0px));\n}\n```\n\n### as an object\n\n`vh-check` allows you to have more control by passing a configuration object.\n\n```js\nvhCheck({\n  cssVarName: 'vh-offset',\n  force: false,\n  bind: true,\n  redefineVh: false,\n  updateOnTouch: false,\n  onUpdate: function noop() {},\n})\n```\n\n#### cssVarName\n\n**type:** `string`  \n**default:** `'vh-offset'`\n\nChange the CSS var name\n\n#### force\n\n**type:** `boolean`  \n**default:** `false`\n\nSet the CSS var even if `100vh` computation is good\n\n#### bind\n\n**type:** `boolean`  \n**default:** `true`\n\nAutomatically bind to `orientationchange` event\n\n#### redefineVh\n\n**type:** `boolean`  \n**default:** `false`\n\nChange the CSS var value.\nInstead of being the total size of the gap, it will be 1% of the real window size.  \nYou can find more explanation in this [CSS Trick article](https://css-tricks.com/the-trick-to-viewport-units-on-mobile/)\n\n⚠️ **Important**\n\nIf you don't set a `cssVarName`, the CSS custom property will be named `vh` instead of `vh-offset`.  \nSo your CSS should be:\n\n```css\n.my-element {\n  height: 100vh;\n  height: calc(var(--vh, 1vh) * 100);\n}\n```\n\n#### updateOnTouch\n\n**type:** `boolean`  \n**default:** `false`\n\nAdd an event listener on `touchmove` to recompute the sizes\n\n⚠️ **Important**\n\n- This can impact your website performances as changing sizes will make your browser [reflow](https://www.sitepoint.com/10-ways-minimize-reflows-improve-performance/)\n- if `options.bind` is `false`, this will be ignored as well\n\n#### onUpdate\n\n**type:** `function`  \n**default:** `function noop(){}`\n\nyou can specify a callback which will be called with an updated `vh-check` object every time a computation occurre.\n\n## about browser support\n\nThis library require [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) which is [IE10+](https://caniuse.com/#search=requestAnimationFrame)\nYou'll need a [polyfill](https://github.com/airwave-development/raf-polyfill) if you want to support older browsers\n\n- **vh unit** – supported since [IE9+](http://caniuse.com/#search=vh)\n- **calc** – supported since [IE9+](https://caniuse.com/#search=calc)\n- **CSS custom properties** – supported since [IE Edge](http://caniuse.com/#feat=css-variables) and iOS 9.3+\n  IE11 \u0026 below will need a fallback without CSS var\n- **concerned browsers** – as for now:\n  - Safari since iOS7+\n  - Chrome Android \u003e= v56\n\nTo sum it up:\n\n| Browser       | Library will work | CSS Custom property |\n| ------------- | :---------------: | :-----------------: |\n| \u003c= IE 9       |        ❌         |         ❌          |\n| IE 10 \u0026 IE 11 |        ✅         |         ❌          |\n| IE Edge       |        ✅         |         ✅          |\n| \u003c iOS 9.3     |        ✅         |         ❌          |\n\n## demo\n\n### github pages\n\nhttps://hiswe.github.io/vh-check/\n\n### local\n\nyou'll need [node](https://nodejs.org/en/)\n\n- clone the project\n- `npm install`\n- `npm start`\n- go to: http://localhost:8080\n\n## caveats\n\n**On iOS only**, Chrome \u0026 Firefox will change dynamically the size of `1vh` depending on the display of the address bar.  \nThus the library will return a `not needed` value.\n\nIf you want to prevent your vh's components to resize, you could fix the size of the unit like this:\n\n```js\nvhCheck({\n  bind: false,\n  redefineVh: true,\n})\n```\n\n```css\n.my-div {\n  height: calc(var(--vh, 1vh) * 100);\n}\n```\n\n## other stuff\n\n### changelog\n\nSee [CHANGELOG.md](https://github.com/Hiswe/vh-check/blob/master/CHANGELOG.md)\n\n### migrating\n\nSee [MIGRATING.md](https://github.com/Hiswe/vh-check/blob/master/MIGRATING.md)\n\n### run the tests\n\n- clone the project\n- `npm install`\n- `npm test`\n\n### thanks\n\n- [Chris Butterworth](https://github.com/ChrisButterworth) for the contribution\n\n### related\n\n- [ios-inner-height](https://www.npmjs.com/package/ios-inner-height)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHiswe%2Fvh-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHiswe%2Fvh-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHiswe%2Fvh-check/lists"}