You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.7 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vesmír</title>
<style>
section{
height: 100vh;
}
#hvezdy{
color: white;
}
.earth-fixed{
padding: 10%;
position: fixed;
width: 500px;
opacity: 0;}
.stars{
position:fixed;
opacity: 0;
}
#hvezdicky{
color: white;
}
#zjeveni{
color: white;
}
#rotace{
color: white;
}
img {
width: 250px;
}
</style>
</head>
<body>
<div id="earth">
<img class="earth-fixed" src="img/img/e1.jpg" alt="">
</div>
<section id="uvod" style="text-align: center; padding-top: 50vh; font-size: 30px;">
before the scroll,<br>there was the void...
</section>
<section id="dark" style="text-align: center; padding-top: 50vh; font-size: 30px; color: grey;">
... then came<br>the dark
</section>
<section id="hvezdy" style="text-align: center; padding-top: 50vh; font-size: 30px; color: grey;">
... few millions years later,<br>the stars emerged
</section>
<section id="zjeveni" style="padding-left: 75%; padding-top: 50vh; font-size: 30px; color: grey;">
and finally,<br>the planet
</section>
<section id="rotace" style="padding-left: 75%; padding-top: 50vh; font-size: 30px; color: grey;">
earth formed
</section>
<script>
function handler () {
let dark = document.querySelector('#dark');
let dark_rect = dark.getBoundingClientRect();
console.log("dark: " + dark_rect.top);
let value = Math.ceil(255 * (dark_rect.top / dark_rect.height));
if (value >= 0 && value <= 255) {
document.body.style.backgroundColor = "rgb(" + value + "," + value + "," + value + ")";
}
let hvezdy = document.querySelector('#hvezdy');
let hvezdy_rect = hvezdy.getBoundingClientRect();
console.log("hvezdy: " + (hvezdy_rect.height - hvezdy_rect.top));
if (hvezdy_rect.height - hvezdy_rect.top > 0) {
let opacity = (hvezdy_rect.top / hvezdy_rect.height);
console.log("Opacity: " + opacity);
}
let zjeveni = document.querySelector('#zjeveni');
let zjeveni_rect = zjeveni.getBoundingClientRect();
let zeme_img = document.querySelector(".earth-fixed");
console.log("zjeveni: " + (zjeveni_rect.height - zjeveni_rect.top));
if (zjeveni_rect.height - zjeveni_rect.top > 0) {
let opacity = 1 - (zjeveni_rect.top / zjeveni_rect.height);
console.log("zjeveni opacity: " + opacity)
zeme_img.style.opacity = opacity;
}
let rotace = document.querySelector('#rotace');
let rotace_rect = rotace.getBoundingClientRect();
console.log("rotace: " + (rotace_rect.height - rotace_rect.top));
if (rotace_rect.height - rotace_rect.top > 0) {
let cislo = Math.ceil(13 * (1 - (rotace_rect.top / rotace_rect.height)));
console.log("cislo: " + cislo);
if (cislo >= 1 && cislo <= 13) {
zeme_img.setAttribute("src", "img/img/e" + cislo + ".jpg");
}
}
}
window.addEventListener('load', handler, false);
window.addEventListener('scroll', handler, false);
window.addEventListener('resize', handler, false);
</script>
</body>
</html>