<div class="wrap">
<header id="header">
header
</header>
<main>
<section class="visual">
<div class="inner">
<div class="circle fade-in"></div>
<div class="triangle fade-in"></div>
<div class="square fade-in"></div>
</div>
</section>
</main>
<div id="to-top">
<span class="material-icons-outlined">expand_less</span>
</div>
</div>
body {
height: 200vh;
}
@import url(https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Round);
header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1000;
background-color: rgba(255, 255, 255, .7);
backdrop-filter: blur(20px);
text-align: center;
line-height: 70px;
font-size: 20px;
font-weight: bold;
}
.visual {
position: relative;
height: 500px;
background: lightpink;
.fade-in {
opacity: 0;
}
.circle {
position: absolute;
top: 150px;
left: 150px;
border-radius: 50%;
width: 200px;
height: 200px;
background: #000;
}
.square {
position: absolute;
bottom: 100px;
right: 162px;
width: 150px;
height: 150px;
background: yellow;
}
.triangle {
position: absolute;
top: 150px;
left: 200px;
border-radius: 50%;
width: 200px;
height: 200px;
background: blue;
}
}
.youtube {
position: relative;
height: 700px;
background-color: #333;
overflow: hidden;
}
.youtube .youtube__area {
width: 1920px;
position: absolute;
left: 50%;
margin-left: calc(1920px / -2);
top: 50%;
margin-top: calc(1920px * 9 / 16 / -2);
}
.youtube .youtube__area::before {
content: "";
display: block;
width: 100%;
height: 0;
padding-top: 56.25%;
}
.youtube .youtube__cover {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
background-image: url("../images/video_cover_pattern.png");
}
#player {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.youtube .inner {
height: inherit;
}
.youtube .floating1 {
position: absolute;
top: 50px;
left: 0;
}
.youtube .floating2 {
position: absolute;
top: 350px;
left: 150px;
}
#to-top {
position: fixed;
bottom: 30px;
right: -50px;
z-index: 9;
width: 42px;
height: 42px;
background-color: #333;
color: #fff;
border: 2px solid #fff;
border-radius: 10px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
View Compiled
const headerEl = document.querySelector("#header");
const toTopEl = document.querySelector("#to-top");
let lastScrollY = window.scrollY;
window.addEventListener(
"scroll",
_.throttle(function () {
const currentScrollY = window.scrollY;
if (currentScrollY > lastScrollY) {
gsap.to(headerEl, {
opacity: 0,
display: 'none',
duration: 0.6
});
gsap.to(toTopEl, {
right: "30px",
duration: 0.2
});
} else {
gsap.to(headerEl, {
opacity: 1,
display: 'block',
duration: 0.6
});
gsap.to(toTopEl, {
right: "-50px",
duration: 0.2
});
}
lastScrollY = currentScrollY;
}, 300),
);
toTopEl.addEventListener("click", function () {
gsap.to(window, {
scrollTo: 0,
});
});
const fadeEls = document.querySelectorAll(".visual .fade-in");
fadeEls.forEach(function (fadeEl, index) {
gsap.to(fadeEl, 1, {
delay: (index + 1) * 0.7,
opacity: 0.5,
});
});