<div class="vh-container">
<div class="vh-line">
</div>
<p class="vh-display">
window.innerHeight = <span id="inner-height">0</span>px
</p>
</div>
<div class="body-container">
<div class="body-line">
</div>
<p class="body-display">
document.body.offsetHeight = <span id="body-offset">0</span>px
</p>
</div>
<div class="information">
endOfPage = <span id="page-end"></span>
<p class="small">(window.innerHeight + window.pageYOffset >= document.body.offsetHeight)</p>
<p>window.pageYOffset = <span id="y-offset">0</span>px</p>
</div>
<footer>
Pen by <a href="https://www.jemimaabu.com" target="_blank" rel="noopener">Jemima Abu</a> <span class="heart">♥</span>
</footer>
@import url("https://fonts.googleapis.com/css2?family=Lato&display=swap");
body {
margin: 0;
height: 250vh;
position: relative;
font-family: "Lato", sans-serif;
background: #f1f1f1;
}
.vh-container {
position: relative;
height: 100vh;
}
.vh-line,
.body-line {
width: 2px;
z-index: 2;
}
.vh-line {
position: absolute;
height: 97vh;
top: 1.5vh;
margin-left: 5px;
background-color: blue;
}
.vh-line:before {
position: absolute;
content: "";
top: -1.5vh;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 15px solid black;
}
.vh-line:after {
position: absolute;
content: "";
bottom: -1.5vh;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 15px solid black;
}
.vh-line:before,
.vh-line:after {
left: -4px;
}
.vh-display {
position: absolute;
height: max-content;
margin: auto;
transform: rotateZ(-90deg) translateX(-50%);
top: 0;
bottom: 0;
left: 25px;
transform-origin: left;
}
.body-container {
position: relative;
}
.body-line {
position: fixed;
top: 1.5vh;
height: 100vh;
right: 0;
margin-right: 5px;
background-color: orange;
}
.body-line:before {
position: fixed;
content: "";
top: 0;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 15px solid black;
}
.body-line:after {
position: fixed;
content: "";
bottom: 0;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 15px solid black;
}
.body-line:before,
.body-line:after {
right: 1px;
}
.body-display {
position: fixed;
height: max-content;
width: 30vh;
text-align: center;
margin: auto;
transform: rotateZ(-90deg);
top: 0;
bottom: 0;
transform-origin: right;
right: 35px;
z-index: 2;
}
#inner-height {
color: blue;
}
#body-offset {
color: orange;
}
.information {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
width: 50%;
max-width: 300px;
height: fit-content;
margin: auto;
text-align: left;
font-weight: bold;
font-family: "Lato", sans-serif;
transition: opacity 500ms;
}
.information .small {
font-size: 0.75rem;
margin: 0;
}
.scroll-container p {
margin: 0;
position: fixed;
right: 0;
font-size: 1.5rem;
}
.previous-scroll-container {
top: var(--previous-count);
}
.current-scroll-container {
top: var(--current-count);
}
footer {
position: absolute;
bottom: 0;
width: 100%;
padding: 1em;
text-align: center;
background-color: #ffdfb9;
}
footer a {
color: inherit;
text-decoration: none;
}
footer .heart {
color: #dc143c;
}
const pageEnd = document.getElementById("page-end");
const innerHeight = document.getElementById("inner-height");
const yOffset = document.getElementById("y-offset");
const bodyOffset = document.getElementById("body-offset");
const handleScroll = () => {
const endOfPage =
window.innerHeight + window.pageYOffset >= document.body.offsetHeight;
yOffset.innerHTML = window.pageYOffset;
if (endOfPage) {
pageEnd.innerHTML = "true";
pageEnd.style.color = "green";
} else {
pageEnd.innerHTML = "false";
pageEnd.style.color = "red";
}
};
var throttleWait;
const throttle = (callback, time) => {
if (throttleWait) return;
throttleWait = true;
setTimeout(() => {
callback();
throttleWait = false;
}, time);
};
window.addEventListener("load", () => {
innerHeight.innerHTML = window.innerHeight;
bodyOffset.innerHTML = document.body.offsetHeight;
});
window.addEventListener("scroll", () => {
throttle(handleScroll, 250);
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.