Skip to content

Instantly share code, notes, and snippets.

@latentflip
Last active August 29, 2015 14:06
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 latentflip/32bab06aa41f81ee37e4 to your computer and use it in GitHub Desktop.
Save latentflip/32bab06aa41f81ee37e4 to your computer and use it in GitHub Desktop.
function canCalcVh() {
//If we don't have this, calc + vh probably won't work anyway.
if (!window.getComputedStyle) return false;
//Create a div element
var dummyDiv = document.createElement('div');
//Ensure it's not visible
dummyDiv.style.visibility = 'hidden';
//Set a calc style on it
dummyDiv.style.height = 'calc(1px + 50vh)'
//Add it to the dom so it gets a style
document.body.appendChild(dummyDiv);
//Get it's actual computed height
var renderedHeight = parseInt(window.getComputedStyle(dummyDiv).height, 10);
//If it's > 0, then calc with vh must be working
return renderedHeight > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment