Preloading JS calculation prior to images loading
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<link href="images/favicon.png" rel="shortcut icon">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<link href="styles.css" rel="stylesheet">
</head>
<script>
window.addEventListener('load', function() {
var headerHeight = document.getElementById('header').clientHeight;
document.getElementById("content").style.paddingTop = headerHeight + "px";
var footerHeight = document.getElementById('footer').clientHeight;
document.getElementById("content").style.paddingBottom = footerHeight + "px";
}, true);
window.addEventListener('resize', function() {
var headerHeight = document.getElementById('header').clientHeight;
document.getElementById("content").style.paddingTop = headerHeight + "px";
var footerHeight = document.getElementById('footer').clientHeight;
document.getElementById("content").style.paddingBottom = footerHeight + "px";
}, true);
</script>
<body>
<h1>H1</h1>
<div id="background"></div>
<header id="header">
<div id="logo"> <a href="/" class="nonblocklink"><img alt="A logo." src="images/logo.png"></a> </div>
<div id="nav">
<ul>
<li id="projects">PROJECTS
<ul>
<li id="one"> <a href="one.html" class="blocklink" target="_self">ONE</a> </li>
</ul>
</li>
</ul>
</div>
</header>
<div id="content">
<div id="cards">
<img src="images/back1.png" alt="" class="cards" />
<img src="images/back2.png" alt="" class="cards" />
<img src="images/back3.png" alt="" class="cards" />
...
CSS
::selection {
background: #D5D5D5;
}
::-moz-selection {
background: #D5D5D5;
}
h1 {
font-family: Arial;
margin-top: 10px;
margin-left: 10px;
padding: 0px;
top: 0;
left: 0;
font-weight: bold;
font-size: 15px;
text-align: left;
position: fixed;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
pointer-events: none;
color: #000000;
z-index: -2;
}
#background {
background-color: #FFFFFF;
margin: 0px;
padding: 0px;
top: 0;
left: 0;
width: 100%;
height: 100%;
position: fixed;
z-index: -1;
}
a.nonblocklink {
text-decoration: none;
color: inherit;
display: inline-block;
}
a.blocklink {
text-decoration: none;
color: inherit;
display: block;
}
#header {
background-color: white;
width: 100%;
position: fixed;
margin: 0px;
padding: 0px;
padding-top: 10px;
top: 0;
left: 0;
text-align: center;
z-index: 10;
}
#logo img {
width: calc(100% - 20px);
}
#logo img:hover {
-webkit-filter: invert(100%) !important;
}
#nav {
width: 100%;
background-color: white;
}
#projects {
display: inline-block;
}
#nav ul {
font-family: Arial;
font-size: 15px;
font-weight: bold;
color: #000000;
list-style-type: none;
text-align: center;
margin: auto;
padding-top: 6px;
padding-right: 0px;
padding-bottom: 10px;
padding-left: 0px;
}
#nav ul ul {
width: calc(100% - 20px);
list-style-type: none;
font-weight: normal;
display: none;
}
#nav ul li:hover>ul {
display: block;
position: absolute;
text-align: center;
margin: 0 auto;
padding-top: 10px;
left: 0;
right: 0;
}
#one {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#one:hover {
background-color: black;
color: white;
}
#footer {
width: 100%;
background-color: white;
position: fixed;
margin: 0px;
bottom: 0;
left: 0;
text-align: center;
z-index: 11;
}
#footer-nav {
width: 100%;
}
#info...