Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2016 12:10
Show Gist options
  • Save anonymous/646584a554200730a07c15a11213c8f7 to your computer and use it in GitHub Desktop.
Save anonymous/646584a554200730a07c15a11213c8f7 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/nabufitipa
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
body {
height:9999px;
width:100%;
background:black;
color:white;
}
p {
position: fixed;
}
</style>
</head>
<body>
<p id="output">.</p>
<script id="jsbin-javascript">
var output = document.getElementById('output');
var barHidden = false;
var navHeight = -1;
var initialHeight = window.innerHeight;
var initialWidth = window.innerWidth;
var check = function() {
if (initialWidth !== window.innerWidth) {
initialHeight = window.innerHeight;
initialWidth = window.innerWidth;
if (barHidden) {
initialHeight -= navHeight;
}
}
var inner = `Inner: ${window.innerHeight}`;
var diff = window.innerHeight - initialHeight;
if (navHeight === -1 && diff !== 0) {
navHeight = Math.abs(diff);
}
if (diff > 30 && diff < 100) {
barHidden = true;
} else {
barHidden = false;
}
output.innerText = `Initial: ${initialHeight}\n${inner}\nDiff: ${diff}\nNav Hidden: ${barHidden}`;
//window.requestAnimationFrame(check);
};
var partialCheck = function() {
if (navHeight !== -1) {
var percent = ((window.innerHeight - initialHeight) / navHeight) * 100
output.innerText = `${percent}%`;
}
window.requestAnimationFrame(partialCheck);
};
window.onresize = check;
check();
window.requestAnimationFrame(partialCheck);
</script>
<script id="jsbin-source-css" type="text/css">body {
height:9999px;
width:100%;
background:black;
color:white;
}
p {
position: fixed;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var output = document.getElementById('output');
var barHidden = false;
var navHeight = -1;
var initialHeight = window.innerHeight;
var initialWidth = window.innerWidth;
var check = function() {
if (initialWidth !== window.innerWidth) {
initialHeight = window.innerHeight;
initialWidth = window.innerWidth;
if (barHidden) {
initialHeight -= navHeight;
}
}
var inner = `Inner: ${window.innerHeight}`;
var diff = window.innerHeight - initialHeight;
if (navHeight === -1 && diff !== 0) {
navHeight = Math.abs(diff);
}
if (diff > 30 && diff < 100) {
barHidden = true;
} else {
barHidden = false;
}
output.innerText = `Initial: ${initialHeight}\n${inner}\nDiff: ${diff}\nNav Hidden: ${barHidden}`;
//window.requestAnimationFrame(check);
};
var partialCheck = function() {
if (navHeight !== -1) {
var percent = ((window.innerHeight - initialHeight) / navHeight) * 100
output.innerText = `${percent}%`;
}
window.requestAnimationFrame(partialCheck);
};
window.onresize = check;
check();
window.requestAnimationFrame(partialCheck);
</script></body>
</html>
body {
height:9999px;
width:100%;
background:black;
color:white;
}
p {
position: fixed;
}
var output = document.getElementById('output');
var barHidden = false;
var navHeight = -1;
var initialHeight = window.innerHeight;
var initialWidth = window.innerWidth;
var check = function() {
if (initialWidth !== window.innerWidth) {
initialHeight = window.innerHeight;
initialWidth = window.innerWidth;
if (barHidden) {
initialHeight -= navHeight;
}
}
var inner = `Inner: ${window.innerHeight}`;
var diff = window.innerHeight - initialHeight;
if (navHeight === -1 && diff !== 0) {
navHeight = Math.abs(diff);
}
if (diff > 30 && diff < 100) {
barHidden = true;
} else {
barHidden = false;
}
output.innerText = `Initial: ${initialHeight}\n${inner}\nDiff: ${diff}\nNav Hidden: ${barHidden}`;
//window.requestAnimationFrame(check);
};
var partialCheck = function() {
if (navHeight !== -1) {
var percent = ((window.innerHeight - initialHeight) / navHeight) * 100
output.innerText = `${percent}%`;
}
window.requestAnimationFrame(partialCheck);
};
window.onresize = check;
check();
window.requestAnimationFrame(partialCheck);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment