All Projects → Hiswe → Vh Check

Hiswe / Vh Check

Licence: mit
mobile vh unit utility

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vh Check

Epiboard
Web Extension — A new tab page extension with material design and useful features 🆕 🎉
Stars: ✭ 262 (-10.58%)
Mutual labels:  chrome
Hackbar2.1.3
the free firefox extions of hackbar v2.1.3 v2.2.9 v2.3.1,hackbar 插件未收费的免费版本。适用于chrome浏览器的HackBar-v2.2.6.zip,HackBar-v2.3.1.zip
Stars: ✭ 276 (-5.8%)
Mutual labels:  chrome
Linux Command
Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。https://git.io/linux
Stars: ✭ 17,481 (+5866.21%)
Mutual labels:  chrome
Androidchromium
chrome browser of android version from chromium open project
Stars: ✭ 2,911 (+893.52%)
Mutual labels:  chrome
Youtubecenter
YouTube Center is a userscript designed to expand the functionality of YouTube. It includes the ability to download the video you're watching, auto selecting your preferred video quality and much more.
Stars: ✭ 2,897 (+888.74%)
Mutual labels:  chrome
Puppetcam
Export puppeteer tab as webm video
Stars: ✭ 279 (-4.78%)
Mutual labels:  chrome
Useragent Switcher
A User-Agent spoofer browser extension that is highly configurable
Stars: ✭ 261 (-10.92%)
Mutual labels:  chrome
Gitark
Dark theme for Github
Stars: ✭ 291 (-0.68%)
Mutual labels:  chrome
Hide Files On Github
Chrome extension - Hide nonessential files from the GitHub file browser
Stars: ✭ 277 (-5.46%)
Mutual labels:  chrome
Body Scroll Lock
Body scroll locking that just works with everything 😏
Stars: ✭ 3,357 (+1045.73%)
Mutual labels:  chrome
Xdebug Helper For Chrome
Easily activate PHP debugging, profiling and tracing with this Xdebug Chrome extension
Stars: ✭ 270 (-7.85%)
Mutual labels:  chrome
Hackbrowserdata
Decrypt passwords/cookies/history/bookmarks from the browser. 一款可全平台运行的浏览器数据导出解密工具。
Stars: ✭ 3,864 (+1218.77%)
Mutual labels:  chrome
Node Chrome
deprecated
Stars: ✭ 284 (-3.07%)
Mutual labels:  chrome
Host Switch Plus
Change the hosts rules in Chrome. It's easy, and effect immediately.
Stars: ✭ 264 (-9.9%)
Mutual labels:  chrome
Adamantium Thief
🔑 Decrypt chromium based browsers passwords, cookies, credit cards, history, bookmarks, autofill. Version > 80 is supported.
Stars: ✭ 283 (-3.41%)
Mutual labels:  chrome
Lighthouse Action
💡🏠 GitHub Action for running @GoogleChromeLabs Lighthouse webpage audits
Stars: ✭ 263 (-10.24%)
Mutual labels:  chrome
Jjb
一个帮助你自动申请京东价格保护的chrome拓展
Stars: ✭ 3,083 (+952.22%)
Mutual labels:  chrome
Fofa view
FOFA Pro view 是一款FOFA Pro 资产展示浏览器插件,目前兼容 Chrome、Firefox、Opera。
Stars: ✭ 291 (-0.68%)
Mutual labels:  chrome
Jest Puppeteer
Run your tests using Jest & Puppeteer 🎪✨
Stars: ✭ 3,267 (+1015.02%)
Mutual labels:  chrome
Searchwithmybrowser
Open Cortana searches with your default browser.
Stars: ✭ 285 (-2.73%)
Mutual labels:  chrome

vh-check

get reliable CSS vh sizes for 1kb gzipped

npm version Build Status

the problem

Browsers don't always compute the vh unit the same way. Some mobile browsers compute the vh CSS unit without taking care of the url bar. That means that a 100vh div will overflow the viewport by the size of the url bar.

This is the current behavior for:

As explained in the chrome post, that make sense but make it hard to have a full hero top block.

This script will measure the difference and put it in a CSS var. You can read more on this css-trick article by Louis Hoebregts

why not use viewport-units-buggyfill?

It's doing a very good job:

https://github.com/rodneyrehm/viewport-units-buggyfill

But it has some problems with media-queries:

https://github.com/rodneyrehm/viewport-units-buggyfill/issues/13

use

as a global variable

<script src="https://unpkg.com/vh-check/dist/vh-check.min.js"></script>
<script>
  (function () {
    // initialize the test
    var test = vhCheck();
  }());
</script>

as a commonJS module

npm install vh-check
var check = require('vh-check')
var test = vhCheck() // return an object (see below)

as a ES module module

npm install vh-check
import vhCheck from 'vh-check'
const test = vhCheck()

how it works

  • It will update the vh-check CSS custom property if needed
  • vh-check will be updated on orientationchange event
  • vh-check will not be updated on scroll event by default

returned object

vh-check will return a full object:

{
  isNeeded: false,
  // wether or not it's needed
  value: 0,
  // the CSS var value
  vh: 480,
  // a 100vh div size
  windowHeight: 480,
  // same value as window.innerHeight
  offset: 0,
  // difference between the above sizes
  recompute: function computeDifference(),
  // call this to programmatically get all the values and set the CSS var
  // - this can be useful if you want to add your own listeners
  //   that will trigger a computation
  unbind: function unbindVhCheckListeners(),
  // call this to remove any window listeners created by vh-check
},

example

in your javascript

vhCheck()

in your CSS

main {
  height: 100vh;
  /* If you need to support browser without CSS var support (<= IE11) */
  height: calc(100vh - var(--vh-offset, 0px));
  /* enable vh fix */
}

configuration

as a string

You can pass the CSS var name as a param to vhCheck() (default vh-offset)

vhCheck('browser-address-bar')

In your CSS you will have to reference:

main {
  min-height: 100vh;
  min-height: calc(100vh - var(--browser-address-bar, 0px));
}

as an object

vh-check allows you to have more control by passing a configuration object.

vhCheck({
  cssVarName: 'vh-offset',
  force: false,
  bind: true,
  redefineVh: false,
  updateOnTouch: false,
  onUpdate: function noop() {},
})

cssVarName

type: string
default: 'vh-offset'

Change the CSS var name

force

type: boolean
default: false

Set the CSS var even if 100vh computation is good

bind

type: boolean
default: true

Automatically bind to orientationchange event

redefineVh

type: boolean
default: false

Change the CSS var value. Instead of being the total size of the gap, it will be 1% of the real window size.
You can find more explanation in this CSS Trick article

⚠️ Important

If you don't set a cssVarName, the CSS custom property will be named vh instead of vh-offset.
So your CSS should be:

.my-element {
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
}

updateOnTouch

type: boolean
default: false

Add an event listener on touchmove to recompute the sizes

⚠️ Important

  • This can impact your website performances as changing sizes will make your browser reflow
  • if options.bind is false, this will be ignored as well

onUpdate

type: function
default: function noop(){}

you can specify a callback which will be called with an updated vh-check object every time a computation occurre.

about browser support

This library require requestAnimationFrame which is IE10+ You'll need a polyfill if you want to support older browsers

  • vh unit – supported since IE9+
  • calc – supported since IE9+
  • CSS custom properties – supported since IE Edge and iOS 9.3+ IE11 & below will need a fallback without CSS var
  • concerned browsers – as for now:
    • Safari since iOS7+
    • Chrome Android >= v56

To sum it up:

Browser Library will work CSS Custom property
<= IE 9
IE 10 & IE 11
IE Edge
< iOS 9.3

demo

github pages

https://hiswe.github.io/vh-check/

local

you'll need node

caveats

On iOS only, Chrome & Firefox will change dynamically the size of 1vh depending on the display of the address bar.
Thus the library will return a not needed value.

If you want to prevent your vh's components to resize, you could fix the size of the unit like this:

vhCheck({
  bind: false,
  redefineVh: true,
})
.my-div {
  height: calc(var(--vh, 1vh) * 100);
}

other stuff

changelog

See CHANGELOG.md

migrating

See MIGRATING.md

run the tests

  • clone the project
  • npm install
  • npm test

thanks

related

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].