Skip to content

Instantly share code, notes, and snippets.

@paceaux
Created February 19, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paceaux/165c19f8a6719ab1f8a0 to your computer and use it in GitHub Desktop.
Save paceaux/165c19f8a6719ab1f8a0 to your computer and use it in GitHub Desktop.
Test if a browser supports VH. Based on the idea from vminpoly: https://github.com/saabi/vminpoly/blob/master/vminpoly.js
supportsVh = function () {
var detector = document.createElement('div'),
winHeight = parseInt(window.innerHeight / 10, 10),
testHeight;
detector.style.height = '10vh'; // set an arbitrarily chosen height
document.getElementsByTagName('body')[0].appendChild(detector); // add the element
testHeight = parseInt(window.getComputedStyle(detector, null).height, 10); //get the computed style of the element
document.getElementsByTagName('body')[0].removeChild(detector); // now remove the element
return (testHeight === winHeight); //return whether the element's computed height and the window's height match
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment