Giter Site home page Giter Site logo

vh-check's Introduction

VH CHECK

Safari iOS has a bug about computing the CSS 100vh value.

This script will measure the difference and put it in a CSS var.

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:

rodneyrehm/viewport-units-buggyfill#13

Use

as a global variable

Download the vh-check.js file and then:

<script src="/vh-check.js"></script>
<script>
  (function () {
    // initialize the test
    var isNeeded = vhCheck('vh-test');
  }());
</script>
commonJS
npm install hiswe/vh-check
var vhCheck   = require('vh-check');
// isNeeded will be true || false
var isNeeded  = vhCheck();

Result

this will set a css var if needed:

.offset {
  height: var(--vh-offset);
}

The CSS var will be updated on orientation change

configuration

You can pass the CSS var name as a param to vhCheck()

vhCheck('ios-gap')

In your CSS you will have to reference:

main {
  min-height: calc(100vh - var(--ios-gap));
}

example

In your javascript

vhCheck()

In your CSS

main {
  /* for browser supporting VH without buggy behaviour & no supporting of CSS var */
  min-height: calc(100vh);
  /* calc will handle correctly an undefined css var */
  /* buggyFill will work on iOS 9.3+ only */
  /* will degrade on a buggy 100vh on older version of iOS */
  min-height: calc(100vh - var(--vh-offset));
}

support

In short: only iOS 9.3+

More details:

demo

  • clone the project
  • npm install
  • npm test
  • go to localhost:8080

vh-check's People

Contributors

hiswe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.