Created
February 19, 2015 21:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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